Shell scripting-few example bourne shell scripts executions


Question:

Shell scripting: few example Bourne shell scripts executions

1. Will the following script execute without any error?

#!/bin/sh

if [ "$USER" ]
then
echo I am $USER
endif

echo Script completed.

2. Does the following script parse the password file and print it out by the user's "realname" "home directory" "login name"?

#!/bin/sh

OLDIFS=$IFS
IFS=:
cat /etc/passwd | while read f1 f2 f3 f4 f5 f6 f7
do
if [ "$f5" ]
then
IFS=,
set -- $f5
echo "$f1 $1 $f6"
IFS=:
fi
done
IFS=$OLDIFS.

Solution Preview :

Prepared by a verified Expert
Data Structure & Algorithms: Shell scripting-few example bourne shell scripts executions
Reference No:- TGS01935019

Now Priced at $20 (50% Discount)

Recommended (97%)

Rated (4.9/5)