omitting space in shell script
HI friends,
I want to find the number of files in a given directory ls -1 directoryname | wc -l It gives the number of files in the given directory. But I want to store the number of files given as output of this command in a shell variable and autoincrement it. Please help. Thanks in advance... |
I think I understand the "store in shell variable" bit, but on the auto-
increment you lost me ... what are you trying to achieve? export LS_NUM=` ls -1 directoryname | wc -l` Cheers. Tink |
Hi,
I think that auto-increment is maybe to count for example the number of files which are under /var. So he may want to do a loop and auto-increment its variable. in that case you can do: LS_NUM+=$(($LS_NUM+` ls -1 directoryname | wc -l`)) or LS_NUM=`expr $LS_NUM + ` ls -1 directoryname | wc -l`` Oliv' |
Note: the execute and put the results here syntax with the `back-ticks` can also be achieved using $(dollar-braces), e.g.
Code:
echo "The number of files is $(ls |wc -l)" When you say "auto-increment" what do you mean? I read that as wanting: Code:
LS_NUM=$(ls |wc -l) |
What does this have to do with omitting space?
|
hi,
I want to treat it as an integer in for loop in shell script. |
Quote:
|
Quote:
Code:
LS_NUM=$(ls |wc -l) |
Yeah, post the script.
|
thanks to all.
problem solved.....:) |
Please post the solution, you got a lot help here & part of the culture of LQ is to post the solution for others to benefit from. Besides, several of your helpers are curious about the triggering problem.
|
All times are GMT -5. The time now is 01:49 AM. |