▲ 3 r/bash
Is using $SHLVL a good way to tell if a script is running in a terminal window?
So, I want to make it so that a script I'm running will ONLY run in a terminal window, and will sleep for 3 seconds then exit if it's not in a terminal window. I've done a little bit of looking, but I'm not entirely sure if it would work as I intend, and if there are ways in which it could fail/if there are more reliable methods.i was thinking of something along the lines of:
If $SHLVL > 1 then
Echo running in terminal
Echo continuing
Elif $SHLVL =< 1 then
Sleep 3
Exit
Else
Echo how is this even possible?
Fi
(Obviously that's not correct syntax, it's just the general structure/idea of what I want to do) I'm not at my PC rn (on a road trip) but I'm trying to write a general test script on my phone that I can test on my PC once I return home.
u/C4n7_7h1nk_0f_n4m3 — 1 day ago