source your script, don’t execute it like ./foo.sh
or sh foo.sh
If you execute your script like that, it is running in sub-shell, not your current.
source foo.sh
would work for you.
More Related Contents:
- shell – remove numbers from a string column [closed]
- What’s the difference between .bashrc, .bash_profile, and .environment?
- How can I parse a YAML file from a Linux shell script?
- How to read a file into a variable in shell?
- Shell command to sum integers, one per line?
- How to make grep only match if the entire line matches?
- How can I execute a command stored in a variable?
- What does $$ mean in the shell?
- Unix time and leap seconds
- What is the $? (dollar question mark) variable in shell scripting? [duplicate]
- How to insert a newline in front of a pattern?
- How do you tell if a string contains another string in POSIX sh?
- How to mark a build unstable in Jenkins when running shell scripts
- Rearrange columns using cut
- How do you catch error codes in a shell pipe?
- How to add timestamp to STDERR redirection
- How can I redirect the output of the “time” command?
- is it possible to use variables in remote ssh command?
- CMake’s execute_process and arbitrary shell scripts
- Permission denied at hdfs
- How to do multiline shell script in Ansible
- How to execute a shell script on a remote server using Ansible?
- What does the line “#!/bin/sh” mean in a UNIX shell script?
- How to grep a text file which contains some binary data?
- How can I pass variables from awk to a shell command?
- Read file into String and do a loop in Expect Script
- How to run a shell script on every request?
- How to run commands via NodeJS child process?
- How to run SWI-Prolog from the command line?
- Exclude specific filename from shell globbing