How to ignore error in command in bash script?

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to ignore error in command in bash script?
# 1  
Old 12-10-2013
How to ignore error in command in bash script?


i have bash script where im cycling some command for different lines in external file.

while read domain;do
nslookupout=$(nslookup -type=ns $domain) || true
another commands
done < filenamewithdomains

i added:
|| true

after the command in belief it will just skip failures.

But i got:
nslookup: '' is not a legal name (empty label)

and it breaken running the script..

please how to achieve so this error is skipped and continuing to the next entry?

i know i can fix my domain list so it dont contains inproper values, but i prefer skipping invalid entries. if anyone know how to remove lines in a file containing two dots at one line by sed, please kindly share.
# 2  
Old 12-10-2013
You can do something like this

your command 2>&1 >/dev/null

# 3  
Old 12-10-2013
I don't see, why your code should not work. The || true even takes care of the situation when the shell's -e option is in effect (assuming another command is not failing while -e is in effect).

However, all entries in the filenamewithdomains should not start with a dot.
# 4  
Old 12-10-2013
You could try...
<your initial code>
set +e
nslookupout=$(nslookup -type=ns $domain) || true
set -e
<your final code>

# 5  
Old 12-10-2013
To remove lines with two or more dots, you can use
sed '/\..*\./d' <input >output

Last edited by hergp; 12-10-2013 at 11:56 AM.. Reason: clarification
# 6  
Old 12-10-2013
Originally Posted by hergp
To remove lines with exactly two dots, you can use
sed '/.*\..*\..*/d' <input >output

and lines with any characters and two or more dots in it?
# 7  
Old 12-10-2013
sed '/\..*\./d' <input >output

works for more than two dots too.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

BASH join command error PLS

i've tried every variation possible and keep getting not sorted error. can anyone shed any light on how to do this? (image attached) (1 Reply)
Discussion started by: deadcick
1 Replies

2. UNIX for Beginners Questions & Answers

How to ignore Case with in COMM command?

Hi, How can i ignore case between 2 files in unix using COMM command. 2 input files are: -bash-4.1$ more x2.txt HELLO hi HI raj -bash-4.1$ more x3.txt hello hi raj COMM command: -bash-4.1$ comm x2.txt x3.txt hello HELLO hi (3 Replies)
Discussion started by: raju2016
3 Replies

3. Shell Programming and Scripting

Ignore exit status for #!/bin/bash -e

I have a file /u/setuplink.txt more setuplink.txt ln -s /u/ ln -s /u/ ln -s /u/ more #!/bin/bash -e echo "START" /u/setuplink.txt echo "END" i wish to exit the for any errors except if the link... (2 Replies)
Discussion started by: mohtashims
2 Replies

4. UNIX for Beginners Questions & Answers

Find command with Ignore Access issues

Hi, I am using following command to find a specific file. find . -name "find*.txt" -type f -print I am issuing that command at root directory since I don't know in which sub folder that file is getting created from some other process. As I am not having access to all directories, my... (3 Replies)
Discussion started by: RameshCh
3 Replies

5. Shell Programming and Scripting

Bash script with awk command ERROR

Hello im new here... Im trying to read file and create folders from words in it but i get this for loop error awk : line 3 : syntax error at or near for my code is.. #!/bin/bash begin for (( i=1;i<=5;i++)); do awk -v i=$i $0 { print $i } mkdir $i done {print $i} end {} i have... (7 Replies)
Discussion started by: boxstep
7 Replies

6. Shell Programming and Scripting

How write the ignore dupkey command in UNIX?

I know that in oracle the is a way to write to ignore the dupkey, something like /*+ ignore_row_on_dupkey_index(tab, index_tab) */ Is there a way to do the same thing but with unix commands? I think there's a way with WHENEVER SQLERROR EXIT SQL.SQLCODE but i'm not sure and i don't know how do... (3 Replies)
Discussion started by: punticci
3 Replies

7. Shell Programming and Scripting

Find command with ignore directory

Dear All, I am using find command find /my_rep/*/RKYPROOF/*/*/WDM/HOME_INT/PWD_DATA -name rk*myguidelines*.pdf -print The problem i am facing here is find /my_rep/*/ the directory after my_rep could be mice001, mice002 and mice001_PO, mice002_PO i want to ignore mice***_PO directory... (3 Replies)
Discussion started by: yadavricky
3 Replies

8. Shell Programming and Scripting

bash syntax error: command not found

I am trying to create a shell that asks the user to enter their name, and compare it to my own by saying we have the same name or saying my name and that they have a nice name too. Here is my script... #!/bin/bash-x echo "Enter your name". read name if then echo "My name is Adam too"... (1 Reply)
Discussion started by: amaxey45
1 Replies

9. Shell Programming and Scripting

#!/bin/bash and #1bin/sh command not found error on mac osx terminal/shell script

i am having a weird error on mac os x running some shell scripts. i am a complete newbie at this and this question concerns 2 scripts. one of which a friend of mine wrote ( a couple weeks ago and it's been running fine on another machine. then last week i wrote and it... (2 Replies)
Discussion started by: danpaluska
2 Replies

10. Ubuntu

set completion-ignore-case on doesn't work in bash

completion-ignore-case option doesn't work in my version: /home/user $ echo $BASH_VERSION 3.2.48(1)-release /home/user $ ls -l * -rw-r--r-- 1 user user 0 2009-10-18 00:09 somefile -rw-r--r-- 1 user user 0 2009-10-18 00:09 Somefile /home/user $ set completion-ignore-case on But when I... (2 Replies)
Discussion started by: Sapfeer
2 Replies
Login or Register to Ask a Question