Results 1 to 10 of 16
Well I run a command in my bashscript using $(COMMAND)
Is there a way to make the program not give ANY output.
For example I give tar a file that ...
- 01-15-2008 #1
Run Command Silent in Bash?
Well I run a command in my bashscript using $(COMMAND)
Is there a way to make the program not give ANY output.
For example I give tar a file that isnt a tar file.
Then it give the error. Its not a tar file. And Aborts
Its fine with me that he aborts. but that output is anoying since I dont want to see that.
So I look in the man page of tar and there isnt a Quite Function.
So, I thought can I maybe do it in another way like:
$(COMMAND) >> /dev/null
or silent($(COMMAND))
I tryed the first one, but not the second one (since thats just rubbish)
Anyhow, is there a way to do something like this?
Thanks,
Cheers,
Robin
- 01-15-2008 #2
I don't think you want the command to give no output, because the
construct is used to collect standard output from the command. For example, when I run this script:Code:$(COMMAND)
I get something like:Code:#!/bin/bash aaa=$(date | rev) echo $aaa $aaa
I think what you want (correct me if I'm wrong) is that standard output should go to the variable, but standard error should be thrown away.Code:8002 TSP 20:20:30 51 naJ euT 8002 TSP 20:20:30 51 naJ euT
In that case, do something like this:
Hope this helps.Code:aaa=$(date | rev 2> /dev/null)
--
Bill
Old age and treachery will overcome youth and skill.
- 01-15-2008 #3
Umm, sorry I think I need to do more explaination.
When I run my script now with the wrong password I get:
And this part of my script does that:Code:bad decrypt 1349:error:<number>:error explain tar: This does not look like a tar archive tar: Skipping to next header tar: Error Exit delayed from previous errors Wrong Passphrase
The Error is a openSSL error that is Hardcoded in the OpenSSL Package to give. (I guess using printf but I guess thats not the point)Code:echo "Enter Passphrase" read -s PASSWORD $(openssl enc -d -aes-256-cbc -salt -in $1 -out container.tar -pass pass:$PASSWORD) $(tar -xf container.tar) shred -zu container.tar if [[ -d container ]]; then rm -rf .container echo "Succesfully Decrypted" else echo " Wrong Passphrase" fi
Anyhow, Id there a way to make openssl shutup?
and tar as well.
- 01-15-2008 #4Just Joined!
- Join Date
- Jul 2007
- Posts
- 41
As wje_lf suggested, if you redirect the output to a file then it will not appear on the command line. If you redirect to /dev/null then the output will be thrown away. There are two sets of output for any program, output 1 gives the standard output and output 2 gives the error output.
So
or justCode:openssl enc -d -aes-256-cbc -salt -in $1 -out container.tar -pass pass:$PASSWORD 1>/dev/null
Will give you no standard outputCode:openssl enc -d -aes-256-cbc -salt -in $1 -out container.tar -pass pass:$PASSWORD >/dev/null
Will give you no error output.Code:openssl enc -d -aes-256-cbc -salt -in $1 -out container.tar -pass pass:$PASSWORD 2>/dev/null
To get neither is a bit different you need to redirect standard output to dev/null then redirect error output to standard output (not the other way around):
Incidentally are you intending to run the output of the commands?Code:openssl enc -d -aes-256-cbc -salt -in $1 -out container.tar -pass pass:$PASSWORD >/dev/null 2>&1
Will untar your file and then try to run the output of the command as a new command. To untar the file you would just need:Code:$(tar -xf container.tar)
Code:tar -xf container.tar
- 01-15-2008 #5
Well, ">/dev/null 2>&1" worked for the OpenSSL one.
Now I run the command aswell on the tar -xf but now my script just crashes.
Anyhow I tryed to Nck everything to Oblivion before with > /dev/null but it just doesnt work.
Anyhow, why does my script crash when I did use the >/dev/null 2&>1
twice?
Cheers,
Thanks
- 01-15-2008 #6Just Joined!
- Join Date
- Jul 2007
- Posts
- 41
Are you still using this?
What this will do will be to run the command:Code:$(tar -xf container.tar >/dev/null 2>&1)
And then attempt to run the output because of the $(). The original command won't produce any output which will probably cause an error when trying to execute the empty second command.Code:tar -xf container.tar >/dev/null 2>&1
Using the redirects twice should not cause your script to crash, could you post your code again?Last edited by thedondj; 01-15-2008 at 11:29 AM. Reason: Clarification
- 01-15-2008 #7
- 01-15-2008 #8Just Joined!
- Join Date
- Jul 2007
- Posts
- 41
What's the error message?
Again I don't understand why you're using the $(...) syntax, is there a good reason for this? Why are you using:
instead ofCode:$(openssl enc -d -aes-256-cbc -salt -in $1 -out container.tar -pass pass:$PASSWORD >/dev/null 2>&1) $(tar -xf container.tar >/dev/null 2>&1)
Code:openssl enc -d -aes-256-cbc -salt -in $1 -out container.tar -pass pass:$PASSWORD >/dev/null 2>&1 tar -xf container.tar >/dev/null 2>&1
- 01-15-2008 #9
- 01-15-2008 #10
Actually, it does matter. It matters because you're going to try variations until you find something that works. If you try those same variations on the $(...) syntax, it's guaranteed to fail, so why do the extra (possibly misleading) work?
It also matters because it's important for future work that you understand what $(...) is supposed to do.
So, once again: Leaving out the $(...) stuff, can you show us your exact script and what output you get?--
Bill
Old age and treachery will overcome youth and skill.


Reply With Quote