2

I have the following script:

#!/bin/sh --
oathtool -b --totp XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX | xclip -sel clip
echo "OTP Copied!"
sleep 2

The oathtool runs when I go to terminal and type something like ./VIP or sh ./VIP. However when I double click the sh file and choose Run in terminal, only the echo and sleep command executes, the oathtool does nothing.

2
  • try using absolute paths... Aug 4, 2019 at 3:10
  • @JoshuaBesneatte, the path is not the troublemaker here, both oathtool and xclip are located in /usr/bin/.
    – pa4080
    Aug 4, 2019 at 8:33

1 Answer 1

2

If you have checked the option Ask each time for the Executable Text File in the Nautilus Preferences, then you will have two options Run in Terminal and Run, when you (double) cluck on an executable by the mouse:

enter image description here

You need to choice Run to achieve what you want. This is also the default behavior if you have set Run executable text files when they are opened in Nautilus Preferences.

These two options Run in Terminal and Run have different behavior, but unfortunately I didn't found any additional documentation. Probably the first one creates a temporal environment that is annihilated when the terminal is closed. We can prove that by adding exec sh at the bottom of your script:

#!/bin/sh --
oathtool -b --totp XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX | xclip -sel clip
echo "OTP Copied!"
sleep 2
exec sh

The command exec sh will replace the current shell (of your script) by a new sh shell, thus the terminal window will be kept open and your clipboard will be active until you are close the terminal window. Another option is to extend the sleep time, then your clipboard will be active while the terminal window sleeps.

If you are using the Run option or custom shortcut I would suggest you to modify your script in this way:

#!/bin/sh --
oathtool -b --totp XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX | xclip -sel clip \
&& notify-send "OTP Copied!"

Thus notify-send will send you a notification within the GUI environment only when the previous command returns true, which is the meaning of &&.


I've tested the described above in Ubuntu 16.04 and 19.04, there is no difference - the same behavior and the proposed solutions are working in both OS.

1
  • 1
    thank you very much! The notify-send method worked well :D Aug 4, 2019 at 10:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .