LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-15-2012, 11:27 AM   #16
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Arch
Posts: 3,013

Rep: Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225

At this point I kind of feel like I'm the only person who has actually read post #1.


Quote:
Originally Posted by Michal Krzyz
Code:
$ sudo echo "TERM=xterm" | sudo tee -a /root/.bashrc > /dev/null
The first sudo is not needed:
Code:
echo "TERM=xterm" | sudo tee -a /root/.bashrc > /dev/null
# Another way is:
sudo bash -c 'echo "TERM=xterm" >> /root/.bashrc'
 
1 members found this post helpful.
Old 12-15-2012, 11:28 AM   #17
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 2,959

Rep: Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268
[QUOTE=Michal Krzyz;4848456]
Code:
...
# no set +e command here
PARTITION_RECORD=$(mount | grep $PARTITION_DEV || echo "")
# no set -e command here
...
I would code that in a way that expresses what I want done with the return code for this particular statement:
Code:
if ! PARTITION_RECORD=$(mount | grep $PARTITION_DEV); then
    echo "$PARTITION_DEV is not mounted" >&2
    exit 1
fi
Putting the statement in the condition part of an "if" construct hides it from the "-e" error handling.

Last edited by rknichols; 12-15-2012 at 11:29 AM.
 
Old 12-16-2012, 12:01 PM   #18
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
Since $(..) runs as a subshell, how about this?

Code:
PARTITION_RECORD=$( set +e ; mount | grep "$PARTITION_DEV" ; true )
There are actually two points of failure involved here. First you need to +e the subshell, so that the it doesn't trip right away when grep fails.

Then when the subshell exits, it inherits the exit value of the final command run, so we just have to stick a true command at the end to keep it from tripping in the main shell too.

BTW, if the format of the returned text isn't important, I'd suggest grepping /etc/mtab directly, rather than mount, and save yourself another level of subshell due to the pipe.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
try/except error handling in bash desromic Programming 4 06-30-2011 04:04 PM
[SOLVED] bash error handling m3phisto Linux - Newbie 4 04-26-2011 08:28 AM
error 127 solution needed vvajeesh Linux - Newbie 4 03-02-2010 11:03 AM
Help needed for error handling in C montylee Programming 11 08-27-2008 11:44 PM
Bash Script and Loop error handling Kedelfor Programming 5 05-22-2005 03:22 PM


All times are GMT -5. The time now is 12:48 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration