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

Problem with parameter 2

Status
Not open for further replies.

eustathi

Technical User
May 9, 2007
9
GR
Hello again

I cant understand why this is working fine

Code:
#!/bin/bash
#line counter
declare -i total=0
for file in $(find  $PWD/*.txt -print)
do
total=$(($total + $(awk 'END { print NR}' $file )))
done
echo $total

and this not for: sh script.sh *.txt

Code:
#!/bin/bash
#line counter
declare -i total=0
for file in $(find  $PWD/"$1" -print)
do
total=$(($total + $(awk 'END { print NR}' $file )))
done
echo $total
 
Hi

[tt]sh script.sh [red]*.txt[/red]
[red]^[/red][/tt]
Because the shell expands this before running the command, so your script will receive in [tt]$1[/tt] the first element resulted from the expansion.

Feherke.
 
so

sh script.sh '*.txt'

should do it...

HTH,

p5wizard
 
I tried this :
Code:
bash-3.00$ sh countsrc.sh '*.txt'
find: /u8/stud2004/eustathi/*.txt: No such file or directory
0
 
Alter script a bit:

Code:
#!/bin/bash
#line counter
declare -i total=0
for file in $(find  $PWD -type f -name "$1" -print)
do
total=$(($total + $(awk 'END { print NR}' $file )))
done
echo $total


HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top