Current location: Hot Scripts Forums » Programming Languages » Perl » SH (Shell Script) Help


SH (Shell Script) Help

Reply
  #1 (permalink)  
Old 02-09-06, 02:17 PM
NixMaster NixMaster is offline
Account Disabled
 
Join Date: Feb 2005
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
SH (Shell Script) Help

Well I didnt see a forum for bash scripting, so I figured this was the closests to it. I've been using the this string for awhile now without problems until today.


Code:
Intfa=`cat /home/user/config.ini | grep -m 1 "Intf=" | sed 's/^[Intf=]*//'`; echo "$Intfa"
Code:
[root@Hostname ~]# Intfa=`cat /home/user/config.ini | grep -m 1 "Intf=" | sed 's/^[Intf=]*//'`; echo "$Intfa"
123.456.789.100
[root@Hostname ~]#
Now that echo's it perfectly

But when I go to use it in my script, It gets all funky, I have narrowed it down to this script. When you add spaces at the end of the variable inside the quotes, it does this.

Code:
[root@Hostname ~]# Intfa=`cat /home/user/config.ini | grep -m 1 "Intf=" | sed 's/^[Intf=]*//'`; echo "$Intfa   "
   .456.789.100
[root@Hostname ~]#

For some reason, how ever many spaces or charectors I put after the variable, it places it at the begining, another example is:

Code:
[root@Hostname ~]# Intfa=`cat /home/user/config.ini | grep -m 1 "Intf=" | sed 's/^[Intf=]*//'`; echo "$Intfa is the IP"
 is the IP9.100
[root@Hostname ~]#


This is the first time this has ever happened, I'm stumped.

Common Answers from other people trying to help:

Dont put the var in quotes while echoing - I have to do this becuase its echoing the variable into another script.
Try to pass the variable to another script - I get the same result.
Use awk in the line - I get the same result.
Include the INI file in the script - Some of the other variables have spaces and do not have quotes (For example: Intf=123.456.789.100) so the variables get messed up if anything above the variable I need has spaces due to it not having quotes.


Any help on this is greatly appreciated. Thanks.

Last edited by NixMaster; 02-09-06 at 02:21 PM.
Reply With Quote
  #2 (permalink)  
Old 02-09-06, 04:22 PM
Millennium's Avatar
Millennium Millennium is offline
Wannabe Coder
 
Join Date: Nov 2003
Posts: 136
Thanks: 0
Thanked 0 Times in 0 Posts
I'm a perl guy so excuse me if I'm just wrong on the face of it.

s/^[Intf=]*//

should you be using square brackets in the above substitution?

Have you tried:

s/^(Intf=)*//

or

s/^Intf=//
Reply With Quote
  #3 (permalink)  
Old 02-09-06, 04:24 PM
NixMaster NixMaster is offline
Account Disabled
 
Join Date: Feb 2005
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
I've also tried without the sed, same result.
Reply With Quote
  #4 (permalink)  
Old 02-09-06, 06:35 PM
Millennium's Avatar
Millennium Millennium is offline
Wannabe Coder
 
Join Date: Nov 2003
Posts: 136
Thanks: 0
Thanked 0 Times in 0 Posts
Well, maybe go over to www.tek-tips.com and find the Unix shell scripting forum and ask over there.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Raffle/Lottery Script (Very profitable!), Coded it myself. Voltaire General Advertisements 6 03-16-09 07:15 AM
2 profitable script sites for sale cms-master.com General Advertisements 3 07-03-07 10:17 AM
Raffle/Lottery Script (Very profitable!), Coded it myself. Voltaire General Advertisements 2 01-02-06 11:55 PM
Is there any integrity of script rankings? webmaster@atmanager.com Hot Scripts Forum Questions, Suggestions and Feedback 17 08-06-04 12:12 AM


All times are GMT -5. The time now is 04:08 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.