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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

echo command and directories

Status
Not open for further replies.

mjpearson

Technical User
Dec 13, 2002
196
US
I'm taking a Linux class at the local Jr. College. The professor says there's a way to get a directory listing by using the 'echo' command. I've researched all my notes. Re-read the manual. Asked classmates.

I can't figure it out. Anyone know the trick to doing this?

mike
 
Hmm, weird...

The command for directory listing is ls...
I guess you could do echo `ls`...

Or maybe echo <TAB> <TAB> to show completions
Then again, you could use any command for that, not just echo.
 
I think I stumbled into it:

'echo *'

file-name-generation will expand the '*' into the independent file names. So when the process begints, all the names are passed to the process as arguments.

An interesting trick.

Thanks,


mike
 
using the shells wild card expantions... that's neat. It's an abuse of echo and the shell though, and the way you want to veiw the files generally speaking is whith ls.

[plug=shameless]
[/plug]
 
'echo *' may be useful when you are troubleshooting a damaged system where /usr/bin has not been mounted yet, and therefore /usr/bin/ls isn't available.
 
Thanks,

I suspect the instructor was trying to teach us two things:

1) As mentioned, the echo is a way to cheat in case the sysatem should get corrupted.

2) It is a way to teach file-name-generatiom. It demonstrates that the commandline is processed independent of the command. After the commanline is expanded THEN the arguments are send to the command/process.

I don't think he spent enough time explaining "why".



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top