I am starting with scripting in ubuntu. Its very easy and good thing to do. In my shell scripting, I need to run few linux command to change directory, or to remove files or copy files or any other command. So I was just wondering is this possible to get the command not found notification in scripting so that if any command fails at any time, we can show error message on terminal to user.
I searched a little about this on google and found out that using below we can read the terminal response:
fooVar=$(ls)
echo "Response: $fooVar"
So above I am running ls
command so on terminal it looks like something:
Response:
folder1
folder2
file1
file2
But if I do something like
fooVar=$(lsv)
echo "Response: $fooVar"
It gives me error lsv command not found
which is ok because lsv
is not a command but this string should come like this
Response: lsv command not found
Is this possible or I am going into wrong way. Also how can we put an if condition for this error. Please help. Thanks