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-30-2005, 11:41 AM   #1
sc_3007
Member
 
Registered: Mar 2005
Location: Kent, England
Distribution: Mandrake 10.1
Posts: 47

Rep: Reputation: 15
Question Shell Scripting Troubles!!!


hey,

I need some help. I am shell scripting at the moment and I have hit a brick wall. I am fairly new to the shell scripting arena and I have a dilema. In a logical statement such as while I am trying to get it to loop when it doesn't recognise the character,

i.e.

while [$variable -ne "C"]
do
...
...
...
done

the only problem is it continuously tells me it needs an integer input. This got me thinking, why dont I convert my character or variable to its corresponding ASCII number.

I decided that I would do this but I am having a hell of a time finding and ASCII value.

Is there a command that can be used to get the ASCII value of a variable???

Many thanks!
 
Old 11-30-2005, 11:53 AM   #2
GrueMaster
Member
 
Registered: Aug 2005
Location: Oregon
Distribution: Kubuntu.
Posts: 848

Rep: Reputation: 30
I think you need to put your variable in quotes. Check the syntax in the Advanced Bash Scripting Manual. This is the manual I use when doing extensive shell scripting (easier to look up things than trying to remember syntax on 7 different languages).
 
Old 11-30-2005, 12:56 PM   #3
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
As I recall, -ne is a comparison for integer values. Bash keeps strict separation between numeric comparison and text comparison. To compare text, use the != operator.

This doesn't answer your question of converting to ASCII, but that's probably not really the road you should take.

For details on all the available operators, issue a man test from the command line.
 
Old 11-30-2005, 01:21 PM   #4
sc_3007
Member
 
Registered: Mar 2005
Location: Kent, England
Distribution: Mandrake 10.1
Posts: 47

Original Poster
Rep: Reputation: 15
Hey, It worked a treat!!! Thanx :>
 
  


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
Shell Scripting: Getting a pid and killing it via a shell script topcat Programming 15 10-28-2007 02:14 AM
shell interface vs shell scripting? I'm confused jcchenz Linux - Software 1 10-26-2005 03:32 PM
shell scripting Prasun1 Linux - General 1 06-23-2005 07:38 AM
Help with Shell Scripting. eggoz Linux - General 2 04-21-2003 01:15 PM
Shell Scripting, I think... AMDPwred Linux - General 1 04-06-2002 12:01 AM

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

All times are GMT -5. The time now is 04:23 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