Bird
Raised Fist0
Linux CLIscripting~20 mins

export command in Linux CLI - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Export Command Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of the export command?
You run the following commands in a Linux shell:
MYVAR=hello
export MYVAR
export
What will be part of the output when you run export?
Linux CLI
MYVAR=hello
export MYVAR
export
AOnly the variable MYVAR=hello is shown
BA list of all exported environment variables including MYVAR=hello
CNo output is shown
DAn error message saying 'export: command not found'
Attempts:
2 left
💡 Hint
The export command without arguments lists all exported variables.
💻 Command Output
intermediate
2:00remaining
What happens when you export a variable with spaces?
Consider the commands:
export MYVAR=hello world
export MYVAR
What will happen when you run these commands in a Linux shell?
Linux CLI
export MYVAR=hello world
export MYVAR
AMYVAR is unset
BMYVAR is set to 'hello world' correctly
CMYVAR is set to 'hello' and 'world' is treated as a separate command
DSyntax error because of the space in the value without quotes
Attempts:
2 left
💡 Hint
Spaces in variable values need quotes.
🔧 Debug
advanced
2:00remaining
Why does this export command not set the variable in the parent shell?
You run this command in your shell:
export MYVAR=hello
Then in a new terminal, you run:
echo $MYVAR
But it prints nothing. Why?
Linux CLI
export MYVAR=hello
# In a new terminal:
echo $MYVAR
ABecause echo command is wrong
BBecause MYVAR was not set correctly
CBecause export only affects the current shell and its child processes, not new terminals
DBecause export clears variables after the command finishes
Attempts:
2 left
💡 Hint
Think about how environment variables are inherited.
🧠 Conceptual
advanced
2:00remaining
What is the effect of 'export -n VAR' in Linux shell?
You have a variable VAR exported. What does the command export -n VAR do?
Linux CLI
export VAR=hello
export -n VAR
AIt removes the export attribute, so VAR is no longer exported to child processes
BIt sets VAR to an empty string
CIt exports VAR with a new value '-n VAR'
DIt causes a syntax error
Attempts:
2 left
💡 Hint
The -n option removes export status.
🚀 Application
expert
2:00remaining
How to export multiple variables in one command correctly?
You want to export two variables VAR1 and VAR2 with values 'foo' and 'bar' in one command. Which command does this correctly?
Aexport VAR1=foo VAR2=bar
Bexport VAR1=foo; export VAR2=bar
Cexport VAR1=foo, VAR2=bar
Dexport VAR1=foo && VAR2=bar
Attempts:
2 left
💡 Hint
Multiple variables can be exported in one export command separated by spaces.

Practice

(1/5)
1. What does the export command do in a Linux shell?
easy
A. Makes a shell variable available to child processes
B. Deletes a shell variable permanently
C. Lists all files in the current directory
D. Changes the current directory

Solution

  1. Step 1: Understand shell variables and environment

    Shell variables exist only in the current shell session unless exported.
  2. Step 2: Role of export

    The export command marks a variable to be passed to child processes as environment variables.
  3. Final Answer:

    Makes a shell variable available to child processes -> Option A
  4. Quick Check:

    export = share variable with child processes [OK]
Hint: Export shares variables with child processes [OK]
Common Mistakes:
  • Thinking export deletes variables
  • Confusing export with file commands
  • Assuming export changes directories
2. Which of the following is the correct syntax to export a variable named PATH with value /usr/local/bin?
easy
A. export =PATH /usr/local/bin
B. export PATH=/usr/local/bin
C. export PATH : /usr/local/bin
D. export PATH == /usr/local/bin

Solution

  1. Step 1: Recall export syntax

    The correct syntax is export VARIABLE=VALUE without spaces around the equal sign.
  2. Step 2: Check each option

    export PATH=/usr/local/bin matches the correct syntax. Others have invalid characters or spaces.
  3. Final Answer:

    export PATH=/usr/local/bin -> Option B
  4. Quick Check:

    export VAR=VALUE no spaces [OK]
Hint: No spaces around = in export syntax [OK]
Common Mistakes:
  • Adding spaces around equal sign
  • Using wrong symbols like : or ==
  • Placing export after assignment
3. What will be the output of the following commands?
MYVAR="hello"
echo $MYVAR
export MYVAR
bash -c 'echo $MYVAR'
medium
A. \n\n
B. hello\n
C. \nhello
D. hello\nhello

Solution

  1. Step 1: Understand variable assignment and export

    First, MYVAR is set to "hello" and printed, so first echo outputs "hello". Then MYVAR is exported.
  2. Step 2: Child shell access

    The bash -c 'echo $MYVAR' runs a new shell which inherits exported variables, so it prints "hello" again.
  3. Final Answer:

    hello hello -> Option D
  4. Quick Check:

    Exported variable visible in child shell [OK]
Hint: Exported vars visible in child shells [OK]
Common Mistakes:
  • Assuming unexported vars appear in child shells
  • Confusing echo outputs with command prompts
  • Ignoring export effect on subshells
4. Identify the error in this script snippet:
export MYVAR
MYVAR="world"
echo $MYVAR
medium
A. echo command is missing quotes
B. export command syntax is wrong
C. MYVAR is exported before assignment, so child shells get empty value
D. No error, script works fine

Solution

  1. Step 1: Analyze export before assignment

    Exporting MYVAR before assigning means MYVAR is empty when exported.
  2. Step 2: Effect on variable value

    Assigning MYVAR after export does not update the exported environment variable for child processes.
  3. Final Answer:

    MYVAR is exported before assignment, so child shells get empty value -> Option C
  4. Quick Check:

    Export before assignment exports empty value [OK]
Hint: Assign before export to share correct value [OK]
Common Mistakes:
  • Exporting before assigning value
  • Thinking export syntax is wrong
  • Assuming echo needs quotes always
5. You want to set a variable CONFIG_PATH to /etc/config and ensure it is available to all scripts run from your current shell session and its children. Which sequence of commands achieves this correctly?
hard
A. CONFIG_PATH=/etc/config\nexport CONFIG_PATH
B. export CONFIG_PATH=/etc/config
C. export CONFIG_PATH\nCONFIG_PATH=/etc/config
D. CONFIG_PATH=/etc/config

Solution

  1. Step 1: Assign variable before export

    Assigning CONFIG_PATH=/etc/config sets the value in the current shell.
  2. Step 2: Export variable after assignment

    Running export CONFIG_PATH marks it for child processes with the assigned value.
  3. Step 3: Check other options

    export CONFIG_PATH=/etc/config works but is less clear; export CONFIG_PATH\nCONFIG_PATH=/etc/config exports before assignment (wrong); CONFIG_PATH=/etc/config does not export.
  4. Final Answer:

    CONFIG_PATH=/etc/config export CONFIG_PATH -> Option A
  5. Quick Check:

    Assign then export to share variable [OK]
Hint: Assign first, then export to share variable [OK]
Common Mistakes:
  • Exporting before assigning value
  • Not exporting variable at all
  • Assuming single export with assignment is always best
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard