Operating System - HP-UX
1837896 Members
3364 Online
110122 Solutions
New Discussion

Re: Syntax error for shell script pipe

 
SOLVED
Go to solution
Carlos Roberto Schimidt
Regular Advisor

Syntax error for shell script pipe

Hi,

I read in this forum about check for standard input, but when I run the script, I got error as follow:

# ./teste.sh
./teste.sh: Syntax error at line 3 : `&' is not expected.


#!/usr/bin/sh
for i in `ls -1`
do
if [ -s "$i" ]
then
print $i
fi
done

I´d apreciate any help.

Tks

Schimidt
4 REPLIES 4
James R. Ferguson
Acclaimed Contributor
Solution

Re: Syntax error for shell script pipe

Hi:

You would get an error. This comes from an older post that was mangled by a Forum database conversion some years ago.

You want:

# if [ -s "$i" ]

...in place of :

# if [ -s "$i" ]

Regards!

...JRF...
Mel Burslan
Honored Contributor

Re: Syntax error for shell script pipe

you need to put your if test condition in square brackets, as in:

if you replace "$i" with ${i}, I think your script has a chance of working.

provided

[ is a [

and

] is a ]

________________________________
UNIX because I majored in cryptology...
Kevin Wright
Honored Contributor

Re: Syntax error for shell script pipe

No idea where you would have got that from, but I think what your trying to do is test if the file exists and is not zero.

if [[ -s $i ]];then
print
fi
done
Carlos Roberto Schimidt
Regular Advisor

Re: Syntax error for shell script pipe

Thanks all,

Now it´s work

# ./teste.sh
No piped input

# echo "test" | ./teste.sh
test
Piped input is

# cat teste.sh
#!/usr/bin/sh
if [ -t 0 ]; then
echo "No piped input"
else
cat -
echo "Piped input is $data"
fi