on this simple script
#!/bin/bash -i
trap 'echo "(ctrl+c was hit)"' INT
while true; do
echo -n "hit Enter..";read
echo "still on loop"
done
if I hit ctrl+c it will exit the loop
if I make it not interactive with 1st line like #!/bin/bash
, it will work!
the problem is I have several scripts (run with "startup applications" stored at ~/.config/autostart
) that only work properly with interactivity enabled #!/bin/bash -i
, mainly because they load the .bashrc
again granted by -i
option.
any tips?
EDIT: I found this on the begging of my ~/.bashrc
file:
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
that prevents loading that file as source in non interactive script, I didnt put it there and I dont know why it is there...
EDIT: so, as the problem is loading what is setup at ~/.bashrc
, but to the script doesnt behave weirdly, I found that scripts started by "startup applications" stored at ~/.config/autostart
, may be run this way:
xterm -e "bash -i -c myScript.sh"
#or
bash -i -c 'xterm -e "myScript.sh"' #this way the title looks better
so the script wont have -i
option, will begin just with #!/bin/bash
to behave properly, and the ~/.bashrc
file will setup the environment properly also.