Sample Header Ad - 728x90

Set environment variable for subshell

26 votes
5 answers
33455 views
I know that I can run a command with an environment variable like this: FOO=bar mycommand I know that I can run commands in a subshell like this: (firstcommand && secondcommand) But can I somehow combine those two? FOO=bar (firstcommand && secondcommand) gives: > sh: syntax error: unexpected "(" at least in busybox shell (ash). **Edit:** Kusalananda suggested FOO=bar sh -c 'first && second' which is indeed a solution. However, I am also interested in alternative answers because I like the subshell syntax because it doesn't require fiddling around with escaping of quotes.
Asked by AndreKR (1228 rep)
Sep 13, 2017, 06:03 PM
Last activity: Jun 26, 2023, 03:45 PM