Share your knowledge at the LQ Wiki.
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-30-2005, 11:41 AM   #1
Registered: Mar 2005
Location: Kent, England
Distribution: Mandrake 10.1
Posts: 47

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


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,


while [$variable -ne "C"]

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
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
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
Registered: Mar 2005
Location: Kent, England
Distribution: Mandrake 10.1
Posts: 47

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


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
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 > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:23 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration