$ md="-l /tmp/test/my dir"
$ ls "$md"
ls: invalid option -- ' '
Try 'ls --help' for more information.
$ md="-l \"/tmp/test/my dir\""
$ ls "$md"
ls: invalid option -- ' '
Try 'ls --help' for more information.
I was wondering why both don't work? Thanks. Note that the value of the variable contains
- an option
-l
- a pathname argument which contains a space
- a space which separates the above two.
My actual problem is: I wrote a script myscript.sh
#! /bin/bash
old_dest=""
while getopts ":l:t" opt; do
case $opt in
l)
old_dest="--link-dest \"$OPTARG\""
;;
esac
done
rsync -a --delete "$old_dest" /path/to/source /path/to/dest
I want to call the script as a command with -l
option.
myscript.sh -l "/media/t/my external hdd/backup/old one"
How should I write the part of the script which assigns to old_dest
?