export
is a Bash builtin, echo
is an executable in your $PATH
. So export
is interpreted by Bash as is, without spawning a new process.
You need to get Bash to interpret your command, which you can pass as a string with the -c
option:
bash -c "export foo=bar; echo \$foo"
ALSO:
Each invocation of bash -c
starts with a fresh environment. So something like:
bash -c "export foo=bar" bash -c "echo \$foo"
will not work. The second invocation does not remember foo
.
Instead, you need to chain commands separated by ;
in a single invocation of bash -c
:
bash -c "export foo=bar; echo \$foo"
Related Posts:
- Cannot connect to the Docker daemon at unix:/var/run/docker.sock. Is the docker daemon running?
- apt-get error: Sub-process /usr/bin/dpkg returned an error code (1)
- “Couldn’t find a file descriptor referring to the console” on Ubuntu bash on Windows
- error: ‘Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)’ — Missing /var/run/mysqld/mysqld.sock
- error: ‘Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)’ — Missing /var/run/mysqld/mysqld.sock
- “E: Unable to locate package python-pip” on Ubuntu 18.04 [duplicate]
- “E: Unable to locate package python-pip” on Ubuntu 18.04 [duplicate]
- “sed” command in bash
- WSL – GEDIT Unable to init server: Could not connect: Connection refused
- How to open some ports on Ubuntu?
- Uncompress tar.gz file
- “Unable to find remote helper for ‘https'” during git clone
- What is the difference between /etc/rc.local and ~/.bashrc?
- Unable to establish SSL connection upon wget on Ubuntu 14.04 LTS
- Telnet [Unable to connect to remote host: Connection refused]
- wget returns “Unable to establish SSL connection”
- Curl : connection refused
- How to install Android SDK on Ubuntu?
- How do I install chkconfig on Ubuntu?
- make -j 8 g++: internal compiler error: Killed (program cc1plus)
- List all mounts in Linux
- How to use sed to extract substring
- How to edit gitignore file
- Adding a new entry to the PATH variable in ZSH
- how to search for a directory from the terminal in ubuntu
- What are the functional differences between .profile .bash_profile and .bashrc
- Difference in sites-available vs sites-enabled vs conf.d directories (Nginx)?
- Job scheduling using crontab, what will happen when computer is shutdown during that time?
- GPG does not have enough entropy
- df says disk is full, but it is not
- Why don’t EC2 ubuntu images have swap?
- Heartbleed: how to reliably and portably check the OpenSSL version?
- Is there a proper way to clear logs?
- What is the debian-sys-maint MySQL user (and more)?
- How should an IT department choose a standard Linux distribution?
- Command line program to test DHCP service
- Amazon Linux: apt-get: command not found
- How do I find all files containing specific text on Linux?
- Where can I find php.ini?
- gzip: stdin: not in gzip format tar: Child returned status 1 tar: Error is not recoverable: exiting now
- How to install grub after installing Windows 10
- Linux: ‘Username’ is not in the sudoers file. This incident will be reported
- How can I exclude directories from grep -R?
- How to exclude a directory in find . command
- Explaining the ‘find -mtime’ command
- using pip3: module “importlib._bootstrap” has no attribute “SourceFileLoader”
- Creating a new directory in C
- mv: cannot stat error : No such file or directory error
- Linux error while loading shared libraries: cannot open shared object file: No such file or directory
- Pseudo-terminal will not be allocated because stdin is not a terminal
- linux command to get size of files and directories present in a particular folder?
- screen Cannot open your terminal ‘/dev/pts/0’ – please check
- TCP congestion control version: HTCP module vs highspeed module in linux kernel
- How to use regex with find command?
- Snort Message – WARNING: No preprocessors configured for policy 0
- Getting stty: standard input: Inappropriate ioctl for device when using scp through an ssh tunnel
- How to make rpm auto install dependencies
- Apache server keeps crashing, “caught SIGTERM, shutting down”
- Wait for user input in C?
- Pipe to/from the clipboard in a Bash script
- Difference between exec, execvp, execl, execv?
- what does -zxvf mean in tar -zxvf filename?
- Retrieve last 100 lines logs
- Configuring Apache for localhost
- Restarting cron after changing crontab file?
- cd into directory without having permission
- How do I know the script file name in a Bash script?
- WordPress can’t find temporary folder, but folder it’s looking at has correct permissions
- WordPress cloning issue
- How to run a server on port 80 as a normal user on Linux?
- Copying a large directory tree locally? cp or rsync?
- Check if port is open or closed on a Linux server?
- Moving an already-running process to Screen
- When does `cron.daily` run?
- Permission denied (publickey). SSH from local Ubuntu to Amazon EC2 server
- How to run a command multiple times, using bash shell?
- LVM dangers and caveats
- How to reconnect to a disconnected ssh session
- Should I quit using Ifconfig?
- How to know from which yum repository a package has been installed?
- SSL Certificate Location on UNIX/Linux
- What is “-bash: !”: event not found”
- tar – Remove leading directory components on extraction
- Keeping a linux process running after I logout
- Force dig to resolve without using cache
- How to list Apache enabled modules?
- How to forcibly close a socket in TIME_WAIT?
- How to check if an RSA public / private key pair match
- How can I monitor hard disk load on Linux?
- What’s the reverse DNS command line utility?
- How to add a security group to a running EC2 Instance?
- How bad is it really to install Linux on one big partition?
- How do I extract login history?
- SSH from A through B to C, using private key on B [closed]
- Is it possible to reboot a Linux OS without rebooting the hardware?
- Does the “bs” option in “dd” really improve the speed?
- What solutions exist to allow the use of revision control for server configuration files? [closed]
- Is there a way to do a remote “ls” much like “scp” does a remote copy?
- Dump a linux process’s memory to file
- What is the difference between /sbin/nologin and /bin/false?