Got a question on the topic? Please share it in the comment section below and our experts will answer it for you. For Edureka Linux Training and Certification Curriculum, Visit the website: bit.ly/2CzTN8u
Many thanks! Glad you liked it ! We are glad to have learners like you . Do subscribe our channel and hit that bell icon to never miss an video from our channel .
Hi Sudheer, There isn't any sort of try/catch in bash (i assume you're using bash), but you can achieve a quite similar behaviour using && or ||. In this example, you want to run fallback_command if a_command fails (returns a non-zero value): a_command || fallback_command And in this example, you want to execute second_command if a_command is successful (returns 0): a_command && second_command They can easily be mixed together by using a subshell, for example, the following command will execute a_command, if it succeeds it will then run other_command, but if a_command or other_command fails, fallback_command will be executed: (a_command && other_command) || fallback_command
Got a question on the topic? Please share it in the comment section below and our experts will answer it for you. For Edureka Linux Training and Certification Curriculum, Visit the website: bit.ly/2CzTN8u
That made my life way better dealing with Shell scripts.. Thanks so much
tnk u team edureka.. u guyz are more helpful to me
Hi Edureka & Upasana ,
For #47, could you please give some examples for inserting debugging statements in a script.
Hi Ankan, run a shell script with -x option.
$ bash -x script-name
$ bash -x script.sh
Hope that helps!
best technical channel for beginner
Excellent lecture - Thanks for this video.
Thanks for this.
Thank you so much, i enjoyed learning sh
Many thanks! Glad you liked it ! We are glad to have learners like you . Do subscribe our channel and hit that bell icon to never miss an video from our channel .
Please explain exception handling in shell script
Hi Sudheer, There isn't any sort of try/catch in bash (i assume you're using bash), but you can achieve a quite similar behaviour using && or ||.
In this example, you want to run fallback_command if a_command fails (returns a non-zero value):
a_command || fallback_command
And in this example, you want to execute second_command if a_command is successful (returns 0):
a_command && second_command
They can easily be mixed together by using a subshell, for example, the following command will execute a_command, if it succeeds it will then run other_command, but if a_command or other_command fails, fallback_command will be executed:
(a_command && other_command) || fallback_command
Can we run the .sh file without the bang line(#!/bin/sh) ?
thank youu!
Nicely explained
for question 11, it is not 'cat $1', it should be 'echo $0'
Hi Chiju, $0 would extend to the name of the shell script, which is not the purpose of the question.