Bash comparing the saved value of "boolean" with what?

I am trying to create a program that takes a single argument, a file, and then checks what happened to the file after 60 seconds. To do this, I need to save the result from -e $1in a variable, and then check it after 60 seconds. I can't seem to get the expression ifto listen to me, and I know this is wrong. For testing purposes, this script immediately displays the result of the comparison. Looking forward to a working example of this, I do not know how many versions I have made from this tiny program. Thank you Tomorrow, any help is much appreciated!

#!/bin/bash
onStartup=$(test -e $1) 
if [ -e "$1" ]; then
    unixtid1=$(date  +"%s" -r "$1") #To check if the file was edited. 
    echo $unixtid1
fi
sleep 3

#Here trying to be able to compare the boolean value stored in the
#start of the script. True/False or 1 or 0? Now, both is actually printed. 
if [[ $onStartup=1 ]]; then
    echo "Exists"
fi

if [[ $onStartup=0 ]]; then
    echo "Does not exists"
fi
+3
source share
1 answer

$? , . , 0 true. script

#!/bin/bash
test -e $1
onStartup=$?

if [ $onStartup -eq 0 ]; then
unixtid1=$(date  +"%s" -r "$1") #To check if the file was edited. 
echo $unixtid1
fi
sleep 3

#Here trying to be able to compare the boolean value stored in the
#start of the script. True/False or 1 or 0?
if [[ $onStartup -eq 0 ]]; then
echo "Exists"
else
echo "Does not exists"
fi

test onStartup. test , .

+5

Source: https://habr.com/ru/post/1719919/


All Articles