terminator14
May 20th, 2010, 12:48 AM
Sorry I couldn't make the title any less confusing. Basically I was writing a script to automate some backups of files I have when I came across a bit of a problem. The simplified version of the problem is this:
I'm trying to understand why the following will not work as expected:
$ ls -l /home/user/space\ file
-rw-r--r-- 1 user user 0 2010-05-19 17:05 /home/user/space file
$ TEST="/home/user/space file"; ls $TEST
ls: cannot access /home/user/space: No such file or directory
ls: cannot access file: No such file or directory
$ TEST="/home/user/space\ file"; ls $TEST
ls: cannot access /home/user/space\: No such file or directory
ls: cannot access file: No such file or directory
$ TEST='/home/user/space file'; ls $TEST
ls: cannot access /home/user/space: No such file or directory
ls: cannot access file: No such file or directory
$ TEST='/home/user/space\ file'; ls $TEST
ls: cannot access /home/user/space\: No such file or directory
ls: cannot access file: No such file or directory
If you haven't noticed the differences, it's every combination of (with/without escape character) and (single/double quotes). As far as I know, at least one of those should have worked (I would have figured either attempt 2 or 4). Any reason why they are not? This is bash version 4.1.5(1) by the way.
I'm trying to understand why the following will not work as expected:
$ ls -l /home/user/space\ file
-rw-r--r-- 1 user user 0 2010-05-19 17:05 /home/user/space file
$ TEST="/home/user/space file"; ls $TEST
ls: cannot access /home/user/space: No such file or directory
ls: cannot access file: No such file or directory
$ TEST="/home/user/space\ file"; ls $TEST
ls: cannot access /home/user/space\: No such file or directory
ls: cannot access file: No such file or directory
$ TEST='/home/user/space file'; ls $TEST
ls: cannot access /home/user/space: No such file or directory
ls: cannot access file: No such file or directory
$ TEST='/home/user/space\ file'; ls $TEST
ls: cannot access /home/user/space\: No such file or directory
ls: cannot access file: No such file or directory
If you haven't noticed the differences, it's every combination of (with/without escape character) and (single/double quotes). As far as I know, at least one of those should have worked (I would have figured either attempt 2 or 4). Any reason why they are not? This is bash version 4.1.5(1) by the way.