In accordo con la risposta di daveraja , ecco uno script bash che risolverà lo scopo.
Considera una situazione se stai usando C-shell e vuoi eseguire un comando senza lasciare il contesto / finestra della C-shell come segue,
Comando da eseguire : cerca la parola esatta "Testing" nella directory corrente in modo ricorsivo solo nei file * .h, * .c
grep -nrs --color -w --include="*.{h,c}" Testing ./
Soluzione 1 : accedere a bash da C-shell ed eseguire il comando
bash
grep -nrs --color -w --include="*.{h,c}" Testing ./
exit
Soluzione 2 : scrivi il comando desiderato in un file di testo ed eseguilo usando bash
echo 'grep -nrs --color -w --include="*.{h,c}" Testing ./' > tmp_file.txt
bash tmp_file.txt
Soluzione 3 : eseguire il comando sulla stessa riga utilizzando bash
bash -c 'grep -nrs --color -w --include="*.{h,c}" Testing ./'
Soluzione 4 : crea uno sciprt (una tantum) e usalo per tutti i comandi futuri
alias ebash './execute_command_on_bash.sh'
ebash grep -nrs --color -w --include="*.{h,c}" Testing ./
Lo script è il seguente,
#!/bin/bash
E_BADARGS=85
if [ ! -n "$1" ]
then
echo "Usage: `basename $0` grep -nrs --color -w --include=\"*.{h,c}\" Testing ."
echo "Usage: `basename $0` find . -name \"*.txt\""
exit $E_BADARGS
fi
TMPFILE=$(mktemp)
argList=""
for arg in "$@"
do
if echo $arg | grep -q " "; then
argList="$argList \"$arg\""
else
argList="$argList $arg"
fi
done
argList=$(echo $argList | sed 's/^ *//')
echo "$argList" >> $TMPFILE
last_command="rm -f $TMPFILE"
echo "$last_command" >> $TMPFILE
check_for_last_line=$(tail -n 1 $TMPFILE | grep -o "$last_command")
if [ "$check_for_last_line" == "$last_command" ]
then
bash $TMPFILE
exit 0
else
echo "Something is wrong"
echo "Last command in your tmp file should be removing itself"
echo "Aborting the process"
exit 1
fi