With the first line (the single quotes) we told the shell to switch off field splitting for the string, so it is ONE string: ls -l *.TXT. This "holds" for exactly one evaluation of the string, therefore a command named ls -l *.TXT (literally!) is searched for - but perhaps not found.
You can try for yourself, execute this in your home dir:
you now have a file awkwardly named ls -l foo in your current directory. Now execute this:
And you will see that in fact this script is called. This in turn means that the whole string, including the whitespace, was intepreted as one field. Remove this script with the command rm "./ls -l foo".
This is all because the quoting protected the string from being subjugated to the field splitting process for one time. Notice, that if the string is interpreted a second time, this protection wears off:
eval is a keyword which restarts the whole parsing process (and hence the field splitting) of the shell when reading this line. The line is interpreted twice and because of this the field splitting takes place (but only on the second pass, as some more intricate examples will show you - you may want to experiment and find out how to prevent/enforce this).
I hope this helps.
bakunin
Hi Bakunin,
This is not correct.
The assignment:
Assigns the string ls -l foo to variable cmd.
During assignment the single quotes are discarded.
Quote:
Each variable assignment shall be expanded for tilde expansion, parameter expansion, command substitution, arithmetic expansion, and quote removal prior to assigning the value.
The quote characters ( <backslash>, single-quote, and double-quote) that were present in the original word shall be removed unless they have themselves been quoted.
If we execute the command
Then, because of the unprotected variable expansion $cmd, the string contained in variable cmd gets field-split.
If the IFS is set to its default value of a space, a TAB and newline (denoted as $' \t\n' in some shells) , then this results in a command ls and two parameters, -l and foo
Last edited by Scrutinizer; 03-04-2017 at 04:06 PM..
I have a multiple file with the following name
like.
file_0.csv
file_1.csv
file_2.csv
file_3.csv
file_4.csv
file_5.csv
file_6.csv
file_7.csv
file_7.csv
file_8.csv
file_9.csv
file_10.csv
file_11.csv
file_12.csv
file_13.csv
file_14.csv (2 Replies)
Hi ,
My problem is that I am not able to list all process id of any process.
If you see pstree command it shows many process id under https. But if I run ps command its not listing all the process id for httpd.
It is just listing the PPID and immediate child process id only. I... (4 Replies)
To find the whole size of a particular directory i use "du -sk /dirname".. but after finding the direcory's size how do i make conditions like if the size of the dir is more than 1 GB i hav to delete some of the files inside the dir (0 Replies)
How can I list the files in a directory and just show the file size, date stamp, timestamp and file name..
I've been trying to ls -lrt the directory to a file and then use the cut command but I'm not having any luck with getting the proper results.. I thought i could use the -f switch and count... (4 Replies)
I want to list all the files in the current directory including those in the subdirectories as well as a single lot in the order of last updated. (Not as separate list given by ls -lRt).
Any suggestion?
Thanks (4 Replies)
Hi ,
I want to list all files in the order of size . Just want to know which files occupies more size and which occupies less size .
Is it possible with ls command ? :)
Thanks,
Arun. (1 Reply)
Hi, I'm trying to write a ksh script to copy a specified number of files from one directory to another.
The files are named in the convention <switchname>_log.<num> and the numbers are sequential single digit onwards. I figured I could find some parameter for ls which would list the files in... (3 Replies)
Does any one know how to get a recursive directory listing in long format (showing owner, group, permission etc) without listing the files contained in the directories.
The following command also shows the files but I only want to see the directories.
ls -lrtR * (4 Replies)