I want to create a script that receives a list of parameters in the following structure:
- The first parameter: file or directory
- The other parameters: the names of the commands in the system, for example
date,pwd,tail,head,ls.
The script will run all the commands (starting from the second parameter) on the file/directory received as the first parameter.
I tried this script but I can't use the commands options like -l -i -n
so how can i do this?
#!/bin/bash
name=$1
shift
for cmd in "$@"
do
if [ -e $name ]
then
echo Executing:$cmd
($cmd $name)2>/dev/null
if [ $? -ne 0 ]
then
echo error
fi
else
exit 7
fi
done