Posts linux force command exit status as true
Post
Cancel

linux force command exit status as true

  • Linux command exit status

Using echo $? to get last executed command exit status

1
2
3
4
$ wget https://www.google.com

$ echo $?
0
  • Call a host that does not exists
1
2
3
4
5
6
7
8
$ wget http://www.dummybla.com/

--2020-09-23 19:00:55--  http://www.dummybla.com/
Resolving www.dummybla.com (www.dummybla.com)... failed: nodename nor servname provided, or not known.
wget: unable to resolve host address ‘www.dummybla.com’

$ echo $?
4
  • Call a host that does not exists and force wget exit status as true
1
2
3
4
5
6
7
8
$ wget http://www.dummybla.com/ || true

--2020-09-23 19:00:55--  http://www.dummybla.com/
Resolving www.dummybla.com (www.dummybla.com)... failed: nodename nor servname provided, or not known.
wget: unable to resolve host address ‘www.dummybla.com’

$ echo $?
0
This post is licensed under CC BY 4.0 by the author.