LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
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.

Notices


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

Rep: Reputation: 0
bash scripting question


Hello everyone,

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 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.


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:~$

Any ideas would be greatly appreciated.

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

Rep: Reputation: 47
Moin

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:
Code:
sed -e 's/[0-9]/& /g'
Jan
 
Old 11-12-2008, 01:57 PM   #3
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
The "for" loop breaking up stuff?
Code:
#!/bin/bash
DEVICE="/dev/lircd1"
REMOTE_NAME="DirectTV_RC16"
CMD="irsend --device=$DEVICE SEND_ONCE $REMOTE_NAME"
$CMD "$@"; $CMD select
exit 0
 
Old 11-13-2008, 01:52 PM   #4
lumak
Member
 
Registered: Aug 2008
Location: Phoenix
Distribution: Arch
Posts: 799
Blog Entries: 32

Rep: Reputation: 111Reputation: 111
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.

Code:
function function_name () {
COMMANDS="$1"
# 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
...
done
...
}

# 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.
 
  


Reply



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

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 04:31 AM.

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