Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with for command

Status
Not open for further replies.

linuxMaestro

Instructor
Jan 12, 2004
183
US
Why is this for command not displaying the ls -al?
root@101 [/backup/backup]# locate ararabi.tar.gz
/backup/backup/weekly/ararabi.tar.gz
/backup/backup/monthly/ararabi.tar.gz
root@101 [/backup/backup]# for i in `locate airarabi.tar.gz`;do `ls -al $i`;done;
-bash: -rw-------: command not found
-bash: -rw-------: command not found
 
Try without the back ticks:
Code:
for i in `locate airarabi.tar.gz`;do ls -al $i;done;



----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
The command
Code:
`ls -al $i`
says: run the command [tt]ls -al $i[/tt], and then treat the output of that command as a command itself.

The output probably looks like:
Code:
-rw------- 5 bob user 4096 Nov 28 2003 /some/directory/airarabi.tar.gz

When treated as a command, that says: run the command [tt]-rw-------[/tt] with the arguments [tt]5 bob bob 4096 Nov 28 2003 /some/directory/airarabi.tar.gz[/tt].

After much searching, your shell, [tt]bash[/tt], decides that there is no command named [tt]-rw-------[/tt] available, and gives you the error:
Code:
-bash: -rw-------: command not found


LKBrwnDBA suggests that you remove the backquotes.

This would cause the [tt]ls -la $i[/tt] command to execute and, rather than attempting to use its output as the name of a command, simply display it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top