FlashKeepers

Bash and Shell · College · College and University

Bash I: Variables, Quoting and Expansion

Bash variables, quoting rules, parameter expansion, command substitution, arithmetic, globbing and exit codes.

About this set

38 basic cards for College Bash and Shell. Set 1 of 2 in Bash. It opens with "How do you assign a value to a variable in Bash?" and "How do you access the value of a variable?". Study it alongside the other College sets below.

38 cards · basic cards · AI-written, checked twice. Edit anything.

Study this set free Look inside first Get FlashKeepers for iPhone

Opens in your browser, no account. Get the iPhone and iPad app · Android app

How do you assign a value to a variable in Bash?
Show answervar=value with no spaces around the equals sign
How do you access the value of a variable?
Show answerPrefix the variable name with a dollar sign: $varname or ${varname}
What characters are allowed in Bash variable names?
Show answerAlphanumeric characters and underscore; first character must be a letter or underscore
How do you remove a variable from the shell environment?
Show answerUse the unset command: unset varname
What is an environment variable?
Show answerA shell variable that is exported and inherited by child processes
How do you export a variable to make it available to child processes?
Show answerUse the export command: export varname
What do single quotes prevent in Bash?
Show answerAll expansions and interpretations; everything inside single quotes is treated literally
Which special characters trigger expansion inside double quotes?
Show answerDollar sign ($) for variable and command substitution, and backtick for command substitution
What happens when you use a variable without quotes if it contains spaces?
Show answerThe variable value undergoes word splitting and pathname expansion (globbing)
What quoting style allows ANSI escape sequences like \n and \t?
Show answer$'...' (ANSI-C quoting)
How do you include a literal single quote inside a single-quoted string?
Show answerEnd the single-quoted string, add an escaped single quote \', then resume: 'can'\''t'
How do you prevent a dollar sign from triggering variable expansion?
Show answerEscape it with a backslash: \$ inside double quotes
What is the result if you expand an unset variable inside double quotes?
Show answerAn empty string
Can backslash escape characters inside single quotes?
Show answerNo; backslash is literal inside single quotes
What is the advantage of using ${var} instead of $var?
Show answerBraces are unambiguous when the variable name is followed by alphanumeric characters

23 more cards in the app

Study this set free