I am trying to use Nautilus Actions to create an alternate copy function that includes Access Control Lists. I got Nautilus Actions working fine, but I am having problems with my bash script. Here is a contrived example of the problem I am having.
Code:
ralph@Lat1:~$ a1=$'this\nis\na\nte st' #Create string with newlines in it.
ralph@Lat1:~$ IFS=$'\n' #Set IFS to find newlines during expansion
ralph@Lat1:~$ a2={$a1} #Expand a1 and set string a2 to the results of the expansion of a1
ralph@Lat1:~$ echo -n {$a1} |xxd
0000000: 7b74 6869 7320 6973 2061 2074 6520 7374 {this is a te st #View the results of expansion of a1. Note that the newlines (0a) have
0000010: 7d } #been changed to spaces (20).
ralph@Lat1:~$ echo -n "$a2" |xxd #a2 was set to the expansion of a1. However, when I view it,
0000000: 7b74 6869 730a 6973 0a61 0a74 6520 7374 {this.is.a.te st #it shows the contents of a1--not the expansion of a1.
0000010: 7d # Double quotes are used to prevent any additional expansion of a2.
The only way to get correct a1 expansion seems to be to include the a1 expansion directly in the "echo" statement. One cannot put the a1 expansion into another variable as I tried to do with the statement a2={$a1}. Apparently the $a1 expansion in this statement didn't work. Can somebody explain this?
Also, note that the only character in IFS is \n (newline). According to the manuals I have read, unquoted expansion ($a1) should replace whitespace characters with the first character of IFS, which is newline. Instead the newline whitespace was replaced by spaces. What am I missing?
Any help is appreciated.
Note: Please excuse the "screwed up" comments in the code above. They were added after it was run, and the web site squeezed out all the spaces that were used for formating. If someone can tell me how to avoid having the spaces squeezed out, I will reformat it to make it more readable.
Bookmarks