I have this script that does different things depending on the parameters you put as the input:
#!/bin/bash
cadena="ls -alis"
while [ $# -e 0 ]
do
case $1 in
-p) [ $cadena = "$cadena | grep $2" ] ;;
-o) [ if [ $2 = 'mida' ] then
$cadena="$cadena -lS"
elif [ $2 = 'inode' ] then
$cadena="$cadena | sort -t 1"
fi
] ;;
-d) [ if [ `expr substr $2 1 1`” = '/' ] then
$cadena="$cadena $2"
elif [ `expr substr $2 1 1`” != '/' ] then
$cadena="$cadena `pwd`/$2"
fi
] ;;
-s) [ $cadena="$cadena > $2" ] ;;
shift 2
esac
done
$cadena
Updated the code with case.
The error is the same one a the beginning, in the line 9 with the elif [ $2 = 'inode' ] then statement, it says incorrect token.
[$# -e 0]needs spaces around the brackets. In general, all[ ]need spaces around, so cross check it because I see more more.ls -alis-->cadena=$(ls -alis)cadena="ls -alis"you are storing a string. If you want this command to be executed then you need to usecadena=$(ls -alis).