8 Command-line argument preprocessing Flashcards

1
Q

Brace expansion

A
  • in bash, not needed for posix

– Distributive law for string expansion

Provides for convenient entry of words with repeated substrings:
$ echo a{b,c,d}e
abe ace ade
$ echo {mgk25,fapp2,rja14}@cam.ac.uk
mgk25@cam.ac.uk fapp2@cam.ac.uk rja14@cam.ac.uk
$ rm slides.{bak,aux,dvi,log,ps}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Tilde expansion

A

Provides convenient entry of home directory pathname:
$ echo ~pb ~/Mail/inbox
/home/pb [username = pb]

[if only use tilde on its own – replace with own home directory]
/homes/mgk25/Mail/inbox

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Parameter and command expansion - shell variable substitution

A
$ OBJFILE=skipjack.o
$ echo ${OBJFILE} ${OBJFILE%.o}.c
skipjack.o skipjack.c
$ echo ${HOME} ${PATH} ${LOGNAME}
/homes/mgk25 /bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin mgk25
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Parameter and command expansion – with the standard output lines of commands

A
$ which emacs
/usr/bin/emacs
$ echo $(which emacs)
/usr/bin/emacs
$ ls -l $(which emacs)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Shorter notations for command and parameter expansion

A

variables without braces

$OBJFILE

and command substitution with grave accent (`)

echo which emacs

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Pathname expansion

A
  • Get access to fname without having to type full fname
  • ? stands for an arbitrary single character
    • stands for an arbitrary sequence of zero or more characters
  • [. . . ] stands for one character out of a specified set. Use “-” to specify range of characters and “!” to complement set. Certain character classes can be named within [:. . . :].

None of the above will match a dot at the start of a filename, which is the naming convention for hidden files.

*.bak

[A-Za-z]*.???

[[:alpha:]]*

[!A-Z] .??*

files//.o

rm -rf .* - recursively delete, delete the .. directory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Quote removal

A

Three quotation mechanisms are available to enter the special characters in command-line arguments without triggering the corresponding shell substitution

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

suppresses all special character meanings

A

‘…’

except for ‘ itself

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

suppresses all special character meanings, except for $ \ `

A

“…”

suppresses including space character

\ - allows insertion of special characters, and suppress special meaning of just the next char

$ – command and variable substitution

` – command substitution

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

suppresses all special character meanings for the immediately
following character

A

\

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

e.g. of quote removal

A

$ echo

’$$$’

”* * * $HOME * * *”

$HOME

$$$ * * * /homes/mgk25 * * * $HOME

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

full C string quoting syntax in bash

A

The bash extension $’…’ provides access to the full C string quoting syntax. For example $’\x1b’ is the ASCII ESC character.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly