What is the best way to determine in a shell whether it is being run interactively or is running a script?
The problem is most workers in my group need to do their work in a common directory. The usual practice has been to add 'cd /workingdirectory' line to their .kshrc files (obviously we usually work in ksh), so that when they log in, they are where they want to be.
This causes problems with scripts that need to be run in other directories, however. Any script that is "shebanged" will automatically switch to the workingdirectory when it is started up. (Not shebanging of course runs the risk that the user is working in an uncompatible shell.)
One solution is to change the .kshrc file lines to something like
[[ $0 = /usr/bin/ksh ]] && cd /workingdirectory
If the default shell is /usr/bin/ksh, then the cd will be executed only for interactive shells. But this requires that the user must stick with this shell. I could figure out which shells use the .kshrc file and test for them all, but I was wondering if there was a better way of determining that the current shell is interactive, rather than running a script.
The problem is most workers in my group need to do their work in a common directory. The usual practice has been to add 'cd /workingdirectory' line to their .kshrc files (obviously we usually work in ksh), so that when they log in, they are where they want to be.
This causes problems with scripts that need to be run in other directories, however. Any script that is "shebanged" will automatically switch to the workingdirectory when it is started up. (Not shebanging of course runs the risk that the user is working in an uncompatible shell.)
One solution is to change the .kshrc file lines to something like
[[ $0 = /usr/bin/ksh ]] && cd /workingdirectory
If the default shell is /usr/bin/ksh, then the cd will be executed only for interactive shells. But this requires that the user must stick with this shell. I could figure out which shells use the .kshrc file and test for them all, but I was wondering if there was a better way of determining that the current shell is interactive, rather than running a script.