|
|||||||
| Linux Operating Systems Talk about all Linux distributions and software here! |
![]() |
|
|
Thread Tools |
|
|
#1 |
|
DriverHeaven Newbie
Join Date: Mar 2005
Posts: 1
Rep Power: 0 ![]() |
Hi felllas,
I am a new member in you company and I really need you help. Can someone: Write and explain a command that uses variable(s), the 'printf' command and backquotes (") in order to print the correct number of files in a directory within a descriptive sentence. For example: 'your current directory (/home/abc123) has 10 files'. Note that your command should be interoperable meaning that it should run correctly for any user without modifying the command itself. Thank you very much |
|
|
|
|
|
#2 |
|
DriverHeaven Junior Member
Join Date: Oct 2004
Posts: 84
Rep Power: 0 ![]() |
I tried this command and it worked:
printf "Your current directory is %s, and it has %s file(s)" ${PWD} `ls -1 | wc -l` Explanation: printf - same that the C function printf. PWD - it's a environment variable which it tells the current directory. To know the value of an env variable you have to put and $ and enclose the name of the variable between {}. ls -1 | wc -l This command (in fact two commands) tell you how many files are in the current directory. ls -1 list the files in the curent directory, the -1 option is for ls prints one file per line. wc is a command used generally to count words, but with the -l option it counts lines. So you need to pass to the output of "ls -1" to "wc -l" therefore you need to use the "|" connection pipe". In order to be able to call a command inside a script line, you need to inclose this command between ``.
__________________
Scar_T - Parasite Coder |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
|
|