LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-27-2008, 12:12 AM   #1
tekgek
LQ Newbie
 
Registered: Feb 2007
Distribution: PCLinuxOS
Posts: 23

Rep: Reputation: 15
using read and setting variables from user input string


Hey, all,
I have been trying to make a script that will let me use read to take user input strings and set them as variables. I came across something on another forum, and modified it, to look like this:

Code:
URL_VISIT=""
read -n 1 -a CHAR -s
while [ "x$CHAR" != "x`echo -e "\e"`" ] ; do
echo $CHAR
URL_VISIT="$URL_VISIT$CHAR"
read -n 1 -a CHAR -s
done
echo Whole input was $URL_VISIT
I know almost nothing about programming, but am trying to learn. Anyway, I get the following error when I try to run my script"

Code:
read: 9: Illegal option -n
so far as I know -n is a legal option, and it works when I type the command manually, so perhaps a problem with the code?

Any help would be great.

Thanks,
Tekgek
 
Old 11-27-2008, 01:10 AM   #2
burschik
Member
 
Registered: Jul 2008
Posts: 159

Rep: Reputation: 31
It works for me. Are you sure you are using the shell you think you are using? Furthermore, it makes no sense to use the array option together with "-n 1", since you are only reading a single character anyway.
 
  


Reply


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
changing variables using user-input Kai' Linux - General 3 04-29-2008 06:04 PM
how to read more than ten arguments of user input in a script new_2_unix Linux - Newbie 5 11-19-2007 03:18 PM
daunting task - read wml input, insert variables into URL, DL page, parse, write file jeffreybluml Programming 1 05-12-2005 06:31 AM
parsing a user input string daphne19 Programming 1 04-22-2004 07:40 AM
Setting perm env. variables for a super user. Tarts Slackware 7 08-02-2003 09:21 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:38 PM.

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