I am initiating myself to shell scripting and I need to ask the user about confirmation.
I have this script, which I don't know why the following command is not working: read -p "Are you sure about this action?" yn
I use it twice, at the beggining of the script and in the middle. The first read works, but the second one... is not wrking...
Btw, my linux distribution is debian 9.3
#!/bin/bash
read -p "holaaa" yn #HERE THE COMMAND WORKS AS EXPECTED
if [[ -e "$1" && -f "$1" ]]; then
while read nom grup permisos fitxer; do
if [ -e $fitxer ]; then
#echo $fitxer
#f=$(stat -c %n $fitxer) #jo voldria fer servir awk...
u=$(stat -c %U $fitxer)
g=$(stat -c %G $fitxer)
p=$(stat -c %a $fitxer)
if [[ "$p" != "$permisos" || "$u" != "$nom" || "$g" != "$grup" ]]; then
echo "Informacio al fitxer: $nom , $grup, $permisos, $fitxer"
echo "Informacio real: $u, $g, $p, $fitxer"
#posar confirmation
read -p "holaaaa" yn #HERE THE COMMAND IS NOT WORKING
chown $u:$g $fitxer
chmod $permisos $fitxer
fi
else
echo "file $fitxer does not exist"
fi
done < "$1"
else
echo "error" >&2
fi
Does anyone know why this happens or what am I doing wrong?
echo "Informacio real: $u, $g, $p, $fitxer"output?readisn't executed because that branch is skipped? Fourth, you never use the variableynanywhere.