It's UWAweek 16 (1st semester, week 7)

helpOSTS

This forum is provided to promote discussion amongst students enrolled in Open Source Tools and Scripting.

Please consider offering answers and suggestions to help other students! And if you fix a problem by following a suggestion here, it would be great if other interested students could see a short "Great, fixed it!"  followup message.

How do I ask a good question?
Displaying the 2 articles in this topic
Showing 2 of 133 articles.
Currently 1 other person reading this forum.


 UWA week 13 (1st semester, week 5) ↓
SVG not supported

Login to reply

👍?
helpful
lab4   (both)
9:54pm Tue 26th Mar, Suan C.

Hi Michael, I extracted the below codes from lab4 and have put down the queries below (after long ______). Apologies as I am still figuring out how to use more interactive editing style (at least with some colors?).

#!/bin/bash

get file name from command line

check if file exists

if file doesn't exist, print error message

if [[ ! -f $1 ]] ______ why we put $1 here? $1 is the first argument? or what are we referring to? can we put $0? then 1>&2 echo ERROR ______ what does &2 here mean? exit 1 else # if file exists, print 3rd line head -n 3 $1 | tail -n 1 fi


SVG not supported

Login to reply

👍?
helpful
lab4   (both)
12:23pm Wed 27th Mar, Michael W.

"Suan Chuah" [email protected] wrote:

Hi Michael, I extracted the below codes from lab4 and have put down the queries below (after long ______). Apologies as I am still figuring out how to use more interactive editing style (at least with some colors?).

#!/bin/bash

get file name from command line

check if file exists

if file doesn't exist, print error message

if [[ ! -f $1 ]] ______ why we put $1 here? $1 is the first argument? or what are we referring to? can we put $0? then 1>&2 echo ERROR ______ what does &2 here mean? exit 1 else # if file exists, print 3rd line head -n 3 $1 | tail -n 1 fi

Hi Suan A better way of saying: 1>&2 echo ERROR is echo ERROR > /dev/stderr The first of these can be used by all Unixes/Linuxes, but is very unobvious syntactically; translation: take the output sent to stdout (file descriptor 1) and send it instead to stderr (file descriptor 2). I therefore prefer the second redirection > /dev/stderr, but it may not be not fully portable. In particular, it is present in Bash and Ksh, but it may be absent in standard Shell (sh). That said, it is present in Dash

Cheers MichaelW

The University of Western Australia

Computer Science and Software Engineering

CRICOS Code: 00126G
Written by [email protected]
Powered by history
Feedback always welcome - it makes our software better!
Last modified  5:07AM Sep 06 2023
Privacy policy