Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 01-23-2017, 11:04 PM   #16
Registered: May 2016
Posts: 222

Rep: Reputation: Disabled

On a side note:

if $(grep -q /dev/sdc1 /proc/mounts)
should be rather like
 if grep -q /dev/sdc1 /proc/mounts; then
assuming one wants to check if sdc1 is mounted.
if cares for the exit status of grep (success or failur), not for the output grep gives.
to put it different:
 grep root /etc/passwd; echo "exit code of grep: $?"
 grep_var=$(grep root /etc/passwd); echo "result of grep: $grep_var"
If the script relies on the stick to be mounted, i would make it exit in case the mount fails:
 mount -U 84B46F79B46F6C9C /mnt/wd || exit 1
|| also tests for the exit code, if the previous command failed, || will make exit 1 be executed (like or: either the right side of || will succeed, or the left side will be executed).
If this is too confusing (and it sure doesn't help much with the actual problem, just test for a successfull execution of mount with if-fi, and exit if mount failed).


error, input, output

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
[SOLVED] Bash scripting to find CPU info and perform action DavidDiepUSC Linux - Newbie 10 03-09-2013 04:55 AM
Script to check for text file is different and perform certain action depam Linux - Newbie 3 11-26-2012 09:54 PM
[SOLVED] Bash: Need help with an if statement to check if a file exists or not. MTAS Programming 16 10-26-2010 12:08 PM
[SOLVED] bash - check if file exists in tree hashbang#! Programming 10 01-21-2010 01:37 PM
Bash Help: Check if file exists richinsc Programming 6 01-09-2009 12:27 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:17 AM.

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