Results 1 to 6 of 6
Hello everyone,
I am borrowing the following bash script for use with my Mythbuntu system.
Code:
#!/bin/sh
REMOTE_NAME=DirectTV_RC16
for digit in $(echo $1 | sed -e 's/./& /g'); do
irsend ...
- 11-12-2008 #1Just Joined!
- Join Date
- Feb 2005
- Posts
- 8
Issue with a for loop in bash script
Hello everyone,
I am borrowing the following bash script for use with my Mythbuntu system.
When I pass a value to the script such as "select", it runs the irsend command once for each letter in the value "select" instead of substituting the entire value and only running the irsend command once. Any ideas how to fix this?Code:#!/bin/sh REMOTE_NAME=DirectTV_RC16 for digit in $(echo $1 | sed -e 's/./& /g'); do irsend --device=/dev/lircd1 SEND_ONCE $REMOTE_NAME $digit sleep 0.4 # note, you may have to tweak the interdigit delay up a bit done irsend --device=/dev/lircd1 SEND_ONCE $REMOTE_NAME OK
Thanks,
Robert
- 11-12-2008 #2Just Joined!
- Join Date
- Feb 2005
- Posts
- 8
For instance, here is the output if I pass "one" to the above script.
Code:robert@myth-dvr:~$ /usr/local/bin/change_channel.sh one irsend: command failed: SEND_ONCE DirectTV_RC16 o irsend: unknown command: "o" irsend: command failed: SEND_ONCE DirectTV_RC16 n irsend: unknown command: "n" irsend: command failed: SEND_ONCE DirectTV_RC16 e irsend: unknown command: "e" robert@myth-dvr:~$
- 11-12-2008 #3Linux Newbie
- Join Date
- Jul 2008
- Posts
- 181
- 11-12-2008 #4Just Joined!
- Join Date
- Feb 2005
- Posts
- 8
Thank you for the RTFM. I will read through it again in an attempt to understand it.
- 11-12-2008 #5Just Joined!
- Join Date
- Feb 2005
- Posts
- 8
Well, I believe I actually understand less about the sed command now that I have read the manpage three times.
Can I infer from your post that the problem I am having is not related to the for loop and in fact is a problem with the sed command in the script? If so, is there some other way to achieve the same result?
- 11-13-2008 #6Linux User
- Join Date
- Jun 2007
- Posts
- 318
I took that piece of code and put it into a script to see what happens. This is what I got:
So the sed command is placing spaces between each letter so that's why you're getting multiple runs instead of one.Code:# ./a.bash select #!/bin/bash -vx echo $1 | sed -e 's/./& /g' + echo select + sed -e 's/./& /g' s e l e c t
Why not take out the sed command entirely:
Code:for digit in $(echo $1); do


Reply With Quote
