|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Echo output from command
Hello i am trying to do some calculation from output command for example Code:
ls -l if [ "$ wc -l" -gt 2 ] then echo "error" else echo "$" fi its something like this which get strings from output command and try to sum total lines of this string if exceed certain number it display error if not it display output from the command please note ls -l is just a example |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
If I understand what you're trying to do, the following should be the syntax you need: Code:
if [ "$(ls -l|wc -l)" -gt 2 ]
then
echo 'error'
else
echo '$'
fiThis won't display the output from the ls command. If you want to display the output from the ls command, change the Code:
"$(ls -l|wc -l)" to: Code:
"$(ls -l|tee /dev/tty|wc -l)" I don't understand why you want the echo "$" ; it is the default normal user shell prompt and may confuse users if it looks like your script produces two shell prompts. |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Quote:
i give Code:
ls -l as example but i want general operator that display output from last run command |
|
#4
|
|||
|
|||
|
Quote:
If you would tell us what you really want to do instead of a fake example that reports an error if there is more than one file (with a name not starting with a period (".")) in a directory, we might be able to give you a template that will actually do what you want done. |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Need help in echo output | ranjancom2000 | Shell Programming and Scripting | 3 | 07-22-2011 05:10 AM |
| echo two command output in the same line | chuikingman | Shell Programming and Scripting | 4 | 01-25-2011 01:38 AM |
| problem with suppressed output to file using echo and tee command | shahanali | Shell Programming and Scripting | 1 | 09-20-2010 07:09 PM |
| Format output from "echo" command | msb65 | UNIX for Dummies Questions & Answers | 2 | 08-05-2010 09:24 PM |
| Echo and a command's output on the same line | codyhazelwood | Shell Programming and Scripting | 7 | 03-23-2010 07:24 PM |
|
|