[SOLVED] Issue: Bash script displays its name upon execution
Linux - NewbieThis 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!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Issue: Bash script displays its name upon execution
Hi everyone,
I just noticed a rather annoying issue. Whenever I run a bash script, the first thing that it does is display the name of the script along with all the arguments passed to it (if there are any). However, nowhere in the script there is anything that provokes that behavior.
See for example:
Code:
gacanepa@debian:~/scripts/bash/tests$ ./if_regex.sh 345-14-45
./if_regex.sh 345-14-45
You provided the following argument: 345-14-45
yes
where if_regex.sh is:
Code:
#!/bin/bash
echo "You provided the following argument: $1"
glob="[[:digit:]][[:digit:]][[:digit:]]-[[:digit:]][[:digit:]]-[[:digit:]][[:digit:]]"
if [[ ${1} == $glob ]]; then
echo "yes"
else
echo "no"
fi
The same issue happens with other scripts as well . Any ideas as to why this is happening?
I can't replicate your results. I created an if_regex.sh executable file and stuck it in /tmp. I then ran it and here is the outcome:
Code:
tmp$ ./if_regex.sh 345-14-45
You provided the following argument: 345-14-45
yes
The script is copied from yours and pasted into the if_regex.sh that I created in /tmp
There are only two differences:
1. I created the script in /tmp %I can't see that that should matter.
2. I made it executable
Code:
chmod ugoa+x if_regex.sh
Other than that I did everything exactly as you did. Maybe we have a difference in our bash profile file?
A true mystery.
jdk
I can't replicate your results. I created an if_regex.sh executable file and stuck it in /tmp. I then ran it and here is the outcome:
Code:
tmp$ ./if_regex.sh 345-14-45
You provided the following argument: 345-14-45
yes
The script is copied from yours and pasted into the if_regex.sh that I created in /tmp
There are only two differences:
1. I created the script in /tmp %I can't see that that should matter.
2. I made it executable
Code:
chmod ugoa+x if_regex.sh
Other than that I did everything exactly as you did. Maybe we have a difference in our bash profile file?
A true mystery.
jdk
I actually thought about the bash profile file but the only modification I made to it was setting vim as my default editor. And that was more than a week ago, whereas I just noticed this "issue" earlier this morning (and I've been scripting all along).
I actually thought about the bash profile file but the only modification I made to it was setting vim as my default editor. And that was more than a week ago, whereas I just noticed this "issue" earlier this morning (and I've been scripting all along).
in Windows (and formerly in DOS) there was an option for the console that would echo every command line after expanding variables, and before executing it. It looks very much like this is what's happening here. Is there a global setting like that for bash? I haven't heard of one yet, but that means nothing ...
You may not believe this, but I just restarted the server and the issue seems to be gone . Who know what was the cause.
Anyway, I will mark the previous answers as helpful so that it adds to the reputation of everyone who tried to help. I really appreciate it.
What you are describing sounds like you have the bash -v option set.
Check ~/.bashrc, ~/.bash_profile, ~/.bash_login, ~/.profile, /etc/profile, /etc/bash.bashrc and see if you are executing a "set -v" command, or "set -o verbose".
Also, if you issued set -v in a login shell or command window, it would have the same effect.
What you are describing sounds like you have the bash -v option set.
Check ~/.bashrc, ~/.bash_profile, ~/.bash_login, ~/.profile, /etc/profile, /etc/bash.bashrc and see if you are executing a "set -v" command, or "set -o verbose".
Also, if you issued set -v in a login shell or command window, it would have the same effect.
Anyway, I will mark the previous answers as helpful so that it adds to the reputation of everyone who tried to help. I really appreciate it.
I don't do reputations (mine is irreparably damaged anyway) but if my post was helpful that's reward enough. There is a new moon tonight so that is obviously the reason for this mysterious behaviour.
jdk
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.