Linux Labs

Bash: text processing and scripts / Stage 5 of 9

Arguments, quotes and file checks

Not running Starting usually ~20 s
Leave the lesson

Step 5 of 7 · on a machine · 4 min

A copy script

The last step comes with no ready-made commands: a script that copes with a name with a space and answers a wrong call.

In ~/args-lab there is save.sh: a shebang and the contract in comments, no body. Finish it in nano or vim. Test each case yourself: with a file, with a directory, with no argument — and right after each run, echo $?. The exercise check will also run the script on paths the task does not mention.

Exercise · do it

Finish the copy script

In ~/args-lab, finish save.sh to the contract in its comments. ./save.sh FILE puts a copy of a regular file into the backup directory under the same name and exits with code 0. With no argument: the line Usage: save.sh FILE on stderr and code 2. If the argument is not a regular file: a message on stderr and code 1.

Sign in and start The machine is available after signing in

Goals · 0 of 3

  • Save a copy of a file with a space in its name not done yet
  • Answer a call with no argument as the contract says not done yet
  • Refuse when the argument is not a regular file not done yet

Step goals

0 of 3
  • Save a copy of a file with a space in its name — not done yet
  • Answer a call with no argument as the contract says — not done yet
  • Refuse when the argument is not a regular file — not done yet
Ubuntu 24.04

Step goals

0 of 3
  • Save a copy of a file with a space in its name — not done yet
  • Answer a call with no argument as the contract says — not done yet
  • Refuse when the argument is not a regular file — not done yet
Loading…