I am writing a shell script that takes argument $1 as a destination directory and $2 as a source directory. Script:
#!/bin/zsh
# readlink is used to get absolute path when relative path is provided
output_path=`readlink -f "${1:-.}"`
src_dir=`readlink -f -- "${2:-~/Downloads}"`
echo "destination dir: $output_path"
echo "source dir: $src_dir"
return
Output:
destination dir: /home/ashwin
source dir:
I get blank in source directory variable.
Changing the default value of src_dir
to the absolute path of folder solves the problem.
Script:
#!/bin/zsh
# readlink is used to get absolute path when relative path is provided
output_path=`readlink -f "${1:-.}"`
src_dir=`readlink -f -- "${2:-/home/ashwin/Downloads}"`
echo "destination dir: $output_path"
echo "source dir: $src_dir"
return
Output:
destination dir: /home/ashwin
source dir: /home/ashwin/Downloads
Also providing ~/Downloads
as an argument to script works fine.
I want to understand the reason why ~/Downloads
as the default value of src_dir
does not work.