shell script question
Steven W. Orr
steveo at syslang.net
Mon Jan 20 09:08:55 EST 2003
On Mon, 20 Jan 2003, Erik Price wrote:
=>Hi,
=>
=>I am probably overlooking something obvious but it seems that when I try
=>to execute a command-line "for" loop, the "do command" part is not
=>executed from the current directory. Is that normal? Here is what I mean:
=>
=>[erikprice at host:/home/erikprice]$ for i in `ls`; do "`which du` -khs
=>$i"; done
=>bash: /bin/du -khs bak: No such file or directory
=>bash: /bin/du -khs bin: No such file or directory
=>bash: /bin/du -khs cvs: No such file or directory
=>bash: /bin/du -khs dev: No such file or directory
=>bash: /bin/du -khs docs: No such file or directory
=>bash: /bin/du -khs down: No such file or directory
=>bash: /bin/du -khs ip-up: No such file or directory
=>bash: /bin/du -khs java: No such file or directory
=>bash: /bin/du -khs mail: No such file or directory
=>bash: /bin/du -khs pub: No such file or directory
=>bash: /bin/du -khs public_html: No such file or directory
=>bash: /bin/du -khs tmp: No such file or directory
=>
=>As you can see in the above, I've had to put `which du` in the "do"
=>section (because for some reason the "du" command isn't found if I don't
=>specify an absolute path), and the filename arguments passed to the "do"
=>section aren't found. If I just type "du -khs bak" then it works fine.
=>
=>My shell is bash 2.05 and I set my $PATH in ~/.bashrc (Gentoo Linux).
=>
=>Thanks,
=>
=>Erik
The quoting is wrong. Do this instead:
for i in `ls`; do `which du` -khs $i; done
The way you had the double quotes caused the shell to think that the
command to be executed would be the output of which concatenated with -khs
followed by the filename.
So it was trying to find a single file to execute called
/bin/du -khs bak
But for the life of me I can't figure out why you are running which in the
first place.
--
-Time flies like the wind. Fruit flies like a banana. Stranger things have -
-happened but none stranger than this. Does your driver's license say Organ
-Donor?Black holes are where God divided by zero. Listen to me! We are all-
-individuals! What if this weren't a hypothetical question? steveo at syslang.net
More information about the gnhlug-discuss
mailing list