Maria Demétrio Maria Demétrio - 1 month ago 19
Bash Question

Shell Scrypt syntax error

I'm trying to make a menu and one of the points is to remove a channel from a list of channels but I keep getting errors.

I'm using sh global.sh and then i choose the option from the menu.
The error it gives me is [1: not found

echo "Say wich channel to remove:"
read channel_remove
if [ $(grep -c $channel_remove channels.txt) -eq 0 ]; then
echo "The channel you want to remove doesn't exist"
else
sed -E "s/$channel_remove//g" channels.txt
fi ;;


Thank you

Answer

You need to use $ inside the script to execute it as a command. Moreover ;; are not required.

echo "Say wich channel to remove:"
            read channel_remove
                if [ $(grep -c $channel_remove channels.txt) -eq 0 ]; then
                    echo "The channel you want to remove doesn't exist"
                else
                            sed -E "s/$channel_remove//g" channels.txt
                    fi
Comments