Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


Search this Thread
Old 11-12-2008, 11:10 AM   #1
LQ Newbie
Registered: Sep 2003
Location: Fernley, NV
Posts: 18

Rep: Reputation: 0
bash scripting question

Hello everyone,

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
irsend --device=/dev/lircd1 SEND_ONCE $REMOTE_NAME select
Currently if I pass a value to the above script such as "one", I get the following results. I would like the script to run the irsend command once and pass the value "one" instead of the below behavior.

robert@myth-dvr:~$ /usr/local/bin/ 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"

Any ideas would be greatly appreciated.

Old 11-12-2008, 01:47 PM   #2
Registered: Jun 2008
Posts: 235

Rep: Reputation: 46

I don't exactly understand, what you want. Which values do you expect as $1? If you want to split the argument into single digits, you first have to assure that the argument is a number. Actually your sed splits every argument (even if it is a number or not) into single characters.

Maybe this sed helps:
sed -e 's/[0-9]/& /g'
Old 11-12-2008, 01:57 PM   #3
Registered: May 2001
Posts: 27,286
Blog Entries: 54

Rep: Reputation: 2854Reputation: 2854Reputation: 2854Reputation: 2854Reputation: 2854Reputation: 2854Reputation: 2854Reputation: 2854Reputation: 2854Reputation: 2854Reputation: 2854
The "for" loop breaking up stuff?
$CMD "$@"; $CMD select
exit 0
Old 11-13-2008, 01:52 PM   #4
Registered: Aug 2008
Location: Phoenix
Distribution: Arch
Posts: 799
Blog Entries: 32

Rep: Reputation: 109Reputation: 109
I think I know what you are trying to do... but I'm not sure...

If you are pressing a number combination 1 2 3 4 that gets cached then translated and separated with your for loop... then you really just need spaces in between them.

function function_name () {
# will automatically loop with each word.  No sed needed.
# if you need to change the field separator to anything other than white space... you need to change an environment variable
# I forgot what it is at the moment.
for digit in $1; do

# Each word will be treated as a separate loop through the for loop. 
function_name "one two three four"
However, it would be better to not have to quote the numbers and just use "$@" in place of "$1"

It's kind of hard to understand what you are trying to do with the for command if you don't tell us more information.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash Scripting: Question About tr tvynr Linux - Software 16 09-01-2006 07:25 AM
Bash scripting question nitroid Programming 3 04-13-2006 07:08 AM
Bash scripting question flagg0204 Programming 1 11-19-2005 03:31 PM
Bash scripting question Hammett Linux - General 4 11-29-2004 06:29 AM
Bash Scripting Question Rezon Programming 2 10-30-2003 10:16 AM

All times are GMT -5. The time now is 07:13 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration