write a shell script to find the largest number from 3 given
numbers.

Answer Posted / md. imran

if [ $# -eq 0 ]
then
echo "$: numbers are not given" >&2
exit 1
fi
LARGEST=$(echo $* |xargs -n1 |sort |head -1)
echo $LARGEST is largest number"

or if you want to take input from a file so type following
cat <filename>|xargs -n1|sort|head -1


Note : In first scipt mistake was in tail -1
right answer is head -1 which i have mentioned there.

thanks

Is This Answer Correct ?    5 Yes 5 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is shell and shell script?

777


What are the 3 standard streams in linux?

764


write a shell script to emulate the Id command of PRIMOS which lists files and directories. It list files first with a header FILES and then directories with a header DIRECTORIES. This command has several options. The main ones are. -file select files only -dir select directories only -reverse sort in reverse order -no_header put no header on the output -brief output the header only -size display the size of each file -help display Id´s syntax and options.

2451


I want to connect to a remote server and execute some commands, how can I achieve this?

787


How to find duplicate record in file using shell script?

1067


Write a script to print the first 10 elements of fibonacci series.

2077


Which shell is the best?

748


What does $$ mean in shell script?

788


What is the difference between grep and egrep?

828


What is the way to do multilevel if-else's in shell scripting?

952


What are the advantages of shell script?

714


how will you find the total disk space used by a specific user?

784


I have to write Shells (Linux + Unix)for publishing packages and reports. Is it possible ? What are the differents executable programs ineed to call ?

1879


Where is bash history?

680


How to replace following lines, catch (DAOException e) { objLogger.error(this.getClass () + "addUpdateIssues() " + e); throw new BOException(5122); } catch (BOException e) { objLogger.error(this.getClass () + "addUpdateIssues() " + e); throw e; } catch (Exception e) { objLogger.error(this.getClass () + "addUpdateIssues() " + e); throw new BOException(5122); } Needs to be changed in to, catch (DAOException e) { AppException.handleException (null, null, e, null, null, null, "BOException", this.getClass() + "addUpdateIssues() ", null, null, null, null, null, null, null, null, 5122); } catch (BOException e) { AppException.handleException (null, null, null, e, null, null, "BOException", this.getClass() + "addUpdateIssues() ", null, null, null, null, null, null, null, null, 0); } catch (Exception e) { AppException.handleException (null, null, null, null, null, e, "BOException", this.getClass() + "addUpdateIssues() ", null, null, null, null, null, null, null, null, 5122); }

2139