1

I have this code:

if  [ -f "/mnt/usb/test/linuxConfig.json" ]
   then
   echo "usb på plats"

What I want is when the file is found ( aka the usb is mounted) to set a variable as true.

I want to write a script that checks if the the usb is mounted and in case is not to try to mount it and if it fails to reboot the pi.

I need the variable to be true or false since I want to use a sleep command as well.

2 Answers 2

2

I don't really see where you want to use that variable as you could easily do everything you might want to do in the correct if-then-else branch:

if [ -f "my/file" ]; then
    echo 'Filen finns tillgänglig / the file is available'
else
    echo 'Filen är inte där / the file is not there'
    mount /mnt/something || { sleep 120; reboot; }
    # or  ... || shutdown -r +2 'Rebooting due to failed mount'
fi

To use a "boolean" variable:

found=0
[ -f "my/file" ] || found=1

if (( !found )); then
    # file was not found
else
    # file was found
fi
1

You can use any nonempty value as "true":

if [ -f /mnt/ust/test/linuxConfig.json ] ; then
    var=1
fi

if [ "$var" ] ; then
    echo Var is true
else
    echo Var is false
fi

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.