Echo output from command

Hello

i am trying to do some calculation from output command

for example

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

If I understand what you're trying to do, the following should be the syntax you need:

if [ "$(ls -l|wc -l)" -gt 2 ]
then
        echo 'error'
else
        echo '$'
fi

This won't display the output from the ls command. If you want to display the output from the ls command, change the

"$(ls -l|wc -l)"

to:

"$(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.

hello

i give

ls -l

as example
but i want general operator that display output from last run command

So use one of the examples I gave you, but replace ls -l and wc -l with the commands you want to use.

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.