PDA

View Full Version : Very basic BASH problem



ml_fan
May 30th, 2009, 01:33 AM
I have looked all over the place and tried a lot of different things but I am unable to get this to work

#!/bin/bash

position="a"

if["$position"=="a"];then
echo "great job"
fi


error message as follows:
./bash_sample.sh: line 5: syntax error near unexpected token `then'
./bash_sample.sh: line 5: `if[$position=="a"];then'

x22
May 30th, 2009, 02:18 AM
#!/bin/bash

position=a

if [ $position = a ];then
echo "great job"
fi


*note spaces:-)

ghostdog74
May 30th, 2009, 02:30 AM
use awk


awk 'BEGIN{
position="a"
if ( position == "a"){
print "ok"
}
}'

you don't have to worry about "=" being a valid equality sign when == is actually what you need.

k2t0f12d
May 30th, 2009, 11:04 AM
I have looked all over the place and tried a lot of different things but I am unable to get this to work

#!/bin/bash

position="a"

if["$position"=="a"];then
echo "great job"
fi


error message as follows:
./bash_sample.sh: line 5: syntax error near unexpected token `then'
./bash_sample.sh: line 5: `if[$position=="a"];then'


package="a"
test "$package" -eq "a" && printf "Great job!"

Habbit
May 30th, 2009, 11:11 AM
package="a"
test "$package" -eq "a" && printf "Great job!"

package="a"
test "x$package" -eq "xa" && printf "Great job!"
So that `test` won't die with "another argument expected" when $package is empty.

k2t0f12d
May 30th, 2009, 11:17 AM
package="a"
test "x$package" -eq "xa" && printf "Great job!"
So that `test` won't die with "another argument expected" when $package is empty.


package="a"
test "$package" == "a" && printf "great job"

no, but I had the wrong operator there. try that

ml_fan
May 30th, 2009, 05:55 PM
#!/bin/bash

position=a

if [ $position = a ];then
echo "great job"
fi


*note spaces:-)

Thank you.