Can a shell script set environment variables of the calling shell? [duplicate]

Use the “dot space script” calling syntax. For example, here’s how to do it using the full path to a script: . /path/to/set_env_vars.sh And here’s how to do it if you’re in the same directory as the script: . set_env_vars.sh These execute the script under the current shell instead of loading another one (which is … Read more

How to determine the current interactive shell that I’m in (command-line)

There are three approaches to finding the name of the current shell’s executable: Please note that all three approaches can be fooled if the executable of the shell is /bin/sh, but it’s really a renamed bash, for example (which frequently happens). Thus your second question of whether ps output will do is answered with “not … Read more

Make a Bash alias that takes a parameter?

Bash alias does not directly accept parameters. You will have to create a function. alias does not accept parameters but a function can be called just like an alias. For example: myfunction() { #do things with parameters like $1 such as mv “$1” “$1.bak” cp “$2” “$1” } myfunction old.conf new.conf #calls `myfunction` By the … Read more