I am new to the Linux environment. After a quick search I could not find a helpful question about the $ operator used in bash scripting. I do not know if this question relates more to the Ubuntu (or other) flavor of Linux, or my oh-so-small programming experience with it.
Basically I thought the ~ operand in Linux was perfectly equivalent to the string '/home/username'. If I try to execute a program after a certain delay by using a bash script and an external C-based program, I am so stuck: I cannot make use of the ~ operand and keep the program indifferent to the user (though the rest of the file path must be respected).
Please provide comments to the following (finding the getIdle sources is left to the reader):
#!/bin/bash
# call.sh
idle=false
idleAfter=30000 # consider idle after 30000 ms
# EXPLAIN THIS - Begin
# Strings that work
# str_getIdle_exe='/home/seb/Documents/Seb/Prjcts/Idle/getidle/src/getIdle'
# str_getIdle_exe="/home/seb/Documents/Seb/Prjcts/Idle/getidle/src/getIdle"
# Strings that don'work
str_getIdle_exe='~/Documents/Seb/Prjcts/Idle/getidle/src/getIdle'
# str_getIdle_exe="~/Documents/Seb/Prjcts/Idle/getidle/src/getIdle"
# EXPLAIN THIS - End
while true; do
idleTimeMillis= $str_getIdle_exe
echo $idleTimeMillis # just for debug purposes.
if [[ $idleTimeMillis -gt $idleAfter && $idle = false ]] ; then
echo "start idle" # or whatever command(s) you want to run...
idle=true
/usr/bin/xflock4
else # just for debug purposes.
echo "not there yet..."
fi
if [[ $idleTimeMillis -lt $idleAfter && $idle = true ]] ; then
echo "end idle" # same here.
idle=false
fi
sleep 1 # polling interval
done
What I am trying to explain is: why the two different strings above execute nicely in a shell, but not when called from a script?
I'm using Linux Mint 17.1 "Rebecca" Xfce (64-bit).
Many, many thanks.