I have a bash script which moves the user calling the script to new working directory.
If I call the script with . ./script.sh cd works, and user gets moved to new directory, but the problem is that script is also using exit command if no argument is passed to it, which results in SSH session of the user getting closed.
How can I change the directory without calling the script with . ./script.sh, or how can I exit the script without killing user session when calling . ./script.sh.
The part of the script that I am having problem is this:
#!/bin/bash
VAR=$1
if [[ "$VAR" == "" ]]; then printf "No argument provided, please provide what you want to check.\n"; exit 1; fi
change_cwd () {
cd $NEWDIR
}
change_cwd
If I call ./script.sh exit works as intended, but directory is changed for script subshell not user, but if I use . ./script.sh then exit kills whole SSH session of the user calling the script.
What would be the ways to resolve this, for both exit and cd to work from bash script, either to change directory on some other way or exit script some other way?
Aucun commentaire:
Enregistrer un commentaire