File and Text Manipulation Utilities 1. Вопрос 1
Which command is used to combine three files into a fourth file?
1 / 1 балл
cat file1 > file2 > file3 | file4
cat file1 > file2 > file3 > file4
cp file1 file2 file3 > file4
cat file1 file2 file3 > file4
Правильно
This is the correct syntax
2. Вопрос 2
Which of the following commands can be used to view the last 15 lines of a file (Select all answers that apply)?
1 / 1 балл
tail -15 some_file
Правильно
This is correct
tail +15 some_file
tail -n15 some_file
Правильно
You don't need the n but it works
tail=15 some_file
3. Вопрос 3
Which of the following commands will replace all instances of the word "dog" with "pig" in the file named some_file and send the output to stdout (Select all answers that apply)?
1 / 1 балл
sed -e s:dog:pig:g some_file
Правильно
You can use either : or / as delimiters
sed -e s/dog/pig/ some_file
sed -e s/dog/pig/g some_file
Правильно
You can use either : or / as delimiters
cat some_file | sed -e s/dog/pig/g
Правильно
You either give the file as an argument or stream it in, no difference in result
4. Вопрос 4
Which commands can be used to print the lines that contain the numbers 0–5 in a file (Select all answers that apply)?
1 / 1 балл
grep [0-5] filename
Правильно
This is correct syntax
grep {0-5} filename
grep [-e0 -e1 -e2 -e3 -e4 -e5] filename
grep [0,1,2,3,4,5] filename
Правильно
This is correct syntax
5. Вопрос 5
Which command is used to extract columns from a file to work on them later?
1 / 1 балл
cut
tr
tee
wc
Правильно
cut extracts columns Test 3
Bash Scripting Test3 1. Вопрос 1
Which of the following commands are equivalent (Select all answers that apply)?
1 / 1 балл
if test -f file.c ; then cat file.c ; fi
Правильно
test is an older construct, probably best not used in modern scripts
if [[ -f file.c ]] ; then cat file.c ; fi
Правильно
The double brackets are in bash, but not sh
if [ -f file.c ] ; then cat file.c ; fi
Правильно
This is standard bash syntax with single brackets
[[ -f file.c ]] && cat file.c
Правильно
You can use such continuations instead of explicit if then else constructs
2. Вопрос 2
Which commands will list all files under the current directory ending in "" (Select all answers that apply)?
Note: Output lists may differ in format.
1 / 1 балл
find . -name "*" -exec ls -l {} ';'
Правильно
This uses the explicit -exec argument to find
find . -name "*" | xargs ls -l
Правильно
This shows the use of xargs
find . -name "*" -ls
Правильно
This uses the -ls option to find
ls -l $(find . -name "*")
Правильно
This substitutes the find command results into ls as arguments
3. Вопрос 3
Functions (subprograms) are useful in bash scripts because (Select all answers that apply):
1 / 1 балл
It is better not to have to call another script to get things done
Правильно
This requires keeping track of more than one file, making sure they are all in the path, etc.
They make things easier to read and comprehend
Правильно
Shorter and less repetitive is always beneficial for comprehension
They eliminate the need to retype the same set of commands more than once
Правильно
This makes things shorter and reduces maintenance as changes are made and helps avoid errors
4. Вопрос 4
How would you get the value of a variable named VAR into a script?
1 / 1 балл
ask VAR
input VAR
accept VAR
read VAR
Правильно
This will read the variable in and then its value can be used as $VAR
5. Вопрос 5
Select the correct statement:
1 / 1 балл
A bash function must be placed before it is used in a script
A bash function can be placed anywhere in a script, before or after it is used
Правильно
bash scripts are not compiled, just interpreted sequentially
Test 4
|