1. what the echo statement expr $a \\* $b does ? Assume expr statement is enclos
ID: 3673657 • Letter: 1
Question
1. what the echo statement expr $a * $b does ? Assume expr statement is enclosed in single quotes.
Select one:
a. Addition
b. Subtraction
c. Multiplication
d. Concatenation
2. What will the command "mv -f first second" do
Select one:
a. it will rename first to second only if second does not already exist
b. it will rename first to second and replace second if it already exists without prompting to the user
c. it will rename first to second and will prompt the user if it already exists
d. it will recursively move all files from first to second if both are directories
3. Which of these commands is(are) correct for cp command?
Select one:
a. cp file1 file2
b. cp file directory
c. cp file,file2 directory
d. A and B
4. The redirection cat < abc implies
Select one:
a. Write file 'cat' to file abc
b. Write standard output to abc
c. Change standard input to abc
d. none of the mentioned
5. What is the use of a pipe
Select one:
a. Several functions can be combined in a single statement.
b. Used to count number of lines
c. Used for pattern matching
d. Both a and c
6. Parameters from command line can be passed to a function
Select one:
a. by using the parameter variables $1, $2, $3...
b. by using the variable names only
c. both (a) and (b)
d. none of the mentioned
Explanation / Answer
1. C) Multiplication
$ a=10 b=5
$ expr $a + $b
15
$ expr $a / $b
2
$ expr $a * $b
expr: syntax error
$ expr $a * $b
50
///////////////////////////////////////////////////////////////////////////////////////////////////////
2. D) it will recursively move all files from first to second if both are directories
The mv command does one thing – it moves a file from one location to another. This can be somewhat misleading, because mv is also used to rename files. How? Simple. Here's an example. Say you have the file testfile in /home/jack/ and you want to rename it to testfile2 (while keeping it in the same location). To do this, you would use the mv command like so:
mv /home/jack/testfile /home/jack/testfile2
or, if you're already within /home/jack:
mv testfile testfile2
The above commands would move /home/jack/testfile to /home/jack/testfile2 – effectively renaming the file. But what if you simply wanted to move the file? Say you want to keep your home directory (in this case /home/jack) free from stray files. You could move that testfile into /home/jack/Documents with the command:
mv /home/jack/testfile /home/jack/Documents/
With the above command, you have relocated the file into a new location, while retaining the original file name.
What if you have a number of files you want to move? Luckily, you don't have to issue the mv command for every file. You can use wildcards to help you out. Here's an example:
You have a number of .mp3 files in your ~/Downloads directory (~/ – is an easy way to represent your home directory – in our earlier example, that would be /home/jack/) and you want them in ~/Music. You could quickly move them with a single command, like so:
mv ~/Downloads/*.mp3 ~/Music/
That command would move every file that ended in .mp3 from the Downloads directory, and move them into the Music directory.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3. D) A and B
Unix: cp command syntax
The syntax is:
By default cp will only copies files.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
4. C) Change standard input to abc
the < abc operation modifies cat's stdin so that its data source is the file abc rather than our keyboard.
command > file: Send the stdout of command to file.
command 1> file: Send the stdout of command to file. Since stdout is FD 1, that's the number we put in front of the redirection operator. This is identical to the previous example, because FD 1 is the default for the > operator.
command < file: Use the contents of file when command reads from stdin.
command 0< file: Use the contents of file when command reads from stdin, exactly as in the previous example, since FD 0 (stdin) is the default for the < operator.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
5. D) both a and c
You can connect two commands together so that the output from one program becomes the input of the next program. Two or more commands connected in this way form a pipe. ( combining functions )
The simplest use of grep is to look for a pattern consisting of a single word. It can be used in a pipe so that only those lines of the input files containing a given string are sent to the standard output.
( pattern mathcing )
////////////////////////////////////////////////////////////////////////////////////////////////////
6. C) both (a) and (b)
Command-Line Arguments
The command-line arguments $1, $2, $3,...$9 are positional parameters, with $0 pointing to the actual command, program, shell script, or function and $1, $2, $3, ...$9 as the arguments to the command.
script also uses various special variables related to command line
cp SOURCE DEST cp SOURCE DIRECTORY cp file1 file2 cp file1 new-file2 cp [options] file1 new-file2
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.