Hello.
Probably this be a silly question, for this reason I'm posting it here, instead of the Bash forum.
This script instead of the loop, opens and closes the terminal screen so fast that I can not see what it did.
The script works fine if I remove the string `date "+%D %R"` from the echo command line.
Also, if I type manually the two lines of the loop in a terminal, I get the expected answer.
Any help will be fully apreciated.
Thanks in advance.
Juan
#!/bin/bash
for (( ; ; ))
do
mac=$(ifconfig wlan0 | grep HWaddr | sed 's/.*HWaddr //')
echo `date "+%D %R"`" MAC ADDRESS local es $mac"
sleep 5m
done
Expected loop does not happens in a bash script. :shock:
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Topics in this forum are automatically closed 6 months after creation.
Expected loop does not happens in a bash script. :shock:
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Re: Expected loop does not happens in a bash script. :shock:
Moved here as this is where the other users knowing bash visit more often.
Re: Expected loop does not happens in a bash script. :shock:
I don't see any problems and it also works perfectly fine for me. What happens if you call it from a terminal?
edit:
Should have tried that myself first It reports a syntax error as it doesn't like your for loop and I totally agree that it isn't nice.
Instead of your for loop, try something like:
Funny really as i ran your code in terminal using './yourscript.sh' and it ran perfectly fine, always believed both did the same thing but apparantly I was wrong.
Code: Select all
sh yourscript.sh
Should have tried that myself first It reports a syntax error as it doesn't like your for loop and I totally agree that it isn't nice.
Instead of your for loop, try something like:
Code: Select all
while true;
do
<code>
done
Re: Expected loop does not happens in a bash script. :shock:
Perhaps try bash yourscript.sh instead; running it with sh while you are using bash syntax is not funnysemicolon wrote:I don't see any problems and it also works perfectly fine for me. What happens if you call it from a terminal?
Code: Select all
sh yourscript.sh
Re: Expected loop does not happens in a bash script. :shock:
Good point, usually it is no problem at all though. What happens if invoked with sh, is that bash mimics the behaviour of older versions of sh. Generally not a good habit though.xenopeek wrote:Perhaps try bash yourscript.sh instead; running it with sh while you are using bash syntax is not funny
I'm more into shell than bash anyways, and... my script works in both bash and sh
To summarize: your script should work fine, if it doesn't try run it in the terminal
Re: Expected loop does not happens in a bash script. :shock:
The only difference when bash is run as sh is the scripts it reads on invocation; all language features are still enabled.xenopeek wrote:Perhaps try bash yourscript.sh instead; running it with sh while you are using bash syntax is not funnysemicolon wrote:I don't see any problems and it also works perfectly fine for me. What happens if you call it from a terminal?
Code: Select all
sh yourscript.sh
Note that /bin/sh on Debian-based distros (such as Mint) is not bash; it is dash.
Try this:
Code: Select all
sudo ln /bin/bash /usr/local/bin/sh
PATH=/usr/local/bin:$PATH
sh -c 'q=qwert; echo "${q/w/W}"'