Explore BrainMass

Explore BrainMass

    Shell scripting: Few parameter expansion related questions

    This content was COPIED from BrainMass.com - View the original, and get the already-completed solution here!

    Give brief answers for the following questions.

    1. Can an until loop sometimes never execute?

    2. Will the following script execute with no errors?

    #!/bin/csh
    for I
    do
    echo $I
    done

    3. Does the following script print to standard output, a list of numbers equal to the number passed on the command line?

    #!/bin/sh

    count=$1

    index=1
    while [ "0$index" -le $count ]
    do
    echo $index
    index=`expr "$index" + 1`
    done

    4. Will the following statement print 'I am glad this class is over' to standard output if the shell variable XYZ is NULL or not set?

    : ${XYZ:?"I am glad this class is over"}

    5. After the statement

    : ${VISUAL:=vi}

    will the value of the shell variable VISUAL always be vi?

    6. Will the following command execute:

    ${VISUAL:+vi} ls

    the command 'ls' if the shell variable VISUAL is not set or null?

    7. Will the following commands send to the line printer all files whose contents contain the text '/bin/sh' if the command to print is lpr ?

    MATCH=`grep -l '/bin/sh' *`
    lpr ${MATCH?"NO files found"}

    © BrainMass Inc. brainmass.com February 24, 2021, 4:31 pm ad1c9bdddf
    https://brainmass.com/computer-science/files/shell-scripting-few-parameter-expansion-related-questions-152465

    Solution Preview

    1. Yes, sometimes an until loop will never execute. Consider the example given below.

    #!/bin/bash
    myvar=5
    until [ $myvar ...

    Solution Summary

    Solution also gives reasons/examples in many cases.

    $2.19

    ADVERTISEMENT