la siguiente línea en mi script bash
cat >> $file_namedame este error:
./l7.sh: línea 12: $file_name: redirección ambigua
https://github.com/vats147/public/blob/main/l7.sh
¿por qué?
En el parámetro file_name debe asignar $1 , que pasará al archivo actual como parámetro de entrada.
#! /bin/bash echo -e " Enter file name : \c" read file_name=$1 if [ -f $file_name ] then if [ -w $file_name ] then echo " type some text data. to quit press enter " #cat > $file_name(single angular bracket use for overwritten) #cat >> $file_name(two angular bracket use for appending a text) cat >> $file_name else echo " file not have write permission" fi else echo "file not exist" fiEstos son argumentos posicionales del script.
Ejecutar ./script.sh Hello World hará
$0 = ./script.sh $1 = Hello $2 = WorldNota
Si ejecuta ./script.sh , $0 dará salida ./script.sh pero si lo ejecuta con bash script.sh dará salida script.sh .