DWQA QuestionsCategory: ServerUnable to understand one of the requirements of Linux bash program: "if there is an error in the running process, you need to discard the error information."
luoling asked 2 months ago

Full title:
Using bash to write a script, the script must use the form of function to calculate 1 + 2 + 3 + 4 + +N is the parameter of the script. If there is no parameter, it will prompt an error. If there is an error in the running process, the error information should be discarded.
An incomprehensible sentence:
If there is an error in the running process, the error message should be discarded.
My understanding:
May be used: > / dev / null
But I don’t know how or where to use it.
Attach my own code (except for the sentence that I can’t understand, everything else has completed the programming requirements)

#!/bin/bash
i=1
sum=0
if [ $# -lt 1 ];then
        Echo "you forgot to enter the script parameters"
else
        while [ $1 -ge $i ]
        do
                sum=$[$sum+$i]
                ((i++));
        done
        echo $sum
        echo $i
fi
187J3X1 replied 2 months ago

There should be examples. Correct input / output wrong input / output

187J3X1 replied 2 months ago

This is the last sentence. I can’t program.

1 Answers
luoling answered 2 months ago

Currently, it has been solved in the script file
Function name $1 2 > / dev / null