if [ $USER=root ]; then echo "hi" else echo "bye" fi
it is giving me the following error
line 5: syntax error near unexpected token `fi'
line 5: `fi'
The correct code:
if [ $USER == "root" ]; then echo "hi; else echo "bye"; fi
Related
how to execute if statement line by line in bash??
for i in $(cat $install_script)
do
if [ "$i" = "$check" ]; then
count=$((count+1))
echo whiptail --title "Install SmartBoard" --yesno "${scripts_name[$count]}" 7 $((${#scripts_name[$count]} + 5))
if (( $? == 0 )); then
skip=false
else
skip=true
fi
fi
if [ "$i" == "$check wifi" ]; then
break
fi
if [ $skip == true ]; then
continue
else
sh -c $i ## process line by line
fi
done
error !!
sh: 1: Syntax error: end of file unexpected (expecting "then")
sh: 1: Syntax error: "then" unexpected
sh: 1: Syntax error: "else" unexpected
sh: 1: Syntax error: "fi" unexpected
i'm not good english so if my posts word be rude Sorry that. :(
I am new to Shell script , I am trying to run a simple code
Input for the test.sh file will be input1 and input2 (For Example ./test_script.sh input1 input2)
#!/bin/bash
export a=$1
export b=$2
if ["$a" -eq ''] && ["$b" -eq '']
then
echo "Please enter an input"
elif ["$a"] && ["$b" -eq '']
then
echo "the value of a is $a"
elif ["$a"] && ["$b"]
then
echo "The value of a is $a and b is $b"
else
print "Something went wrong "
fi
Is this syntax correct because I am getting an error , Need help to find where I am going wrong
./test.sh 10 11
./test.sh: line 5: [10: command not found
./test.sh: line 10: [10]: command not found
./test.sh: line 14: [10]: command not found
./test.sh: line 19: print: command not found
I googled a lot and found it because of the spaces within the if condition but then even after resolving that, it still gives me some errors as I've pasted below. Just beginning to learn bash scripts any help would be useful. Thanks.
#!/bin/bash
msg=3;
if[ $msg -gt 0 ]
then
echo $msg;
fi
ERROR
line 3: if[ 3 -gt 0 ]: command not found
line 4: syntax error near unexpected token `then'
line 4: `then'
You missed a space after if:
if [ $msg -gt 0 ]
To better format your code:
msg=3
if [ $msg -gt 0 ]; then
echo $msg;
fi
I am trying to write a simple bash script with a for-loop inside an if-else statement. The following code works:
if [ $# -le 0 ]; then
echo 'No arguments provided.'
else
echo "Arguments detected."
fi
But as soon as I replace the second echo with a for-loop, it breaks:
if [ $# -le 0 ]; then
echo 'No arguments provided.'
else
for i in "$#"
do
echo "Arguments detected: $i"
done
fi
I've tried to execute only the for-loop and I'm given an error, so I think the for-loop is wrong somehow, but I don't know how. The error is:
bash: C:/Users/Angleton/.bashrc: line 45: syntax error near unexpected token `fi'
bash: C:/Users/Angleton/.bashrc: line 45: ` fi'
I have this simple bash script that keeps failing with the following messages:
./servo.sh: line 7: syntax error near unexpected token then'
./servo.sh: line 7: if[ "$level" -eq 1 ]; then'
And my bash script:
#!/bin/bash
level=1
while :
do
if[ $level -eq 1 ]; then
echo "hello"
else
echo "else"
fi
done
What am I doing wrong?
add a space between the if and the [