LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices

Reply
 
Search this Thread
Old 10-14-2012, 09:21 PM   #1
waddles
Member
 
Registered: Sep 2012
Posts: 372

Rep: Reputation: 1
String manipulation won't work in script but will if extracted


Using Slackware 13.37 w/ bash 4.1.10.
Using the following commands in a bash script fails with:
syntax error near unexpected token `}'

bash-4.1$ pknt=789 <-----added for interactive mode
bash-4.1$ jj="00000$pknt"
bash-4.1$ jj=`echo ${jj-3)}` <-----error??
bash-4.1$ echo $jj
789
but as U can C it works fine when cut and pasted in interactive mode.
Tried as ${jj: -3} but gets same error.
Did I leave out some command to tell bash I would use string manipulation or is this a bug?
If there is a sad face it is covering ""

Last edited by waddles; 10-14-2012 at 09:24 PM.
 
Old 10-14-2012, 09:23 PM   #2
willysr
Senior Member
 
Registered: Jul 2004
Location: Jogja, Indonesia
Distribution: Slackware-Current
Posts: 2,618

Rep: Reputation: 444Reputation: 444Reputation: 444Reputation: 444Reputation: 444
Do you mind pasting the code here? It would make debugging easier
 
Old 10-14-2012, 09:30 PM   #3
T3slider
Senior Member
 
Registered: Jul 2007
Distribution: Slackware64-14.1
Posts: 2,297

Rep: Reputation: 722Reputation: 722Reputation: 722Reputation: 722Reputation: 722Reputation: 722Reputation: 722
Are you using
Code:
#!/bin/sh
instead of
Code:
#!/bin/bash
at the start of the script? I think parameter expansion like this may be a bashism...though I could be wrong.
 
Old 10-15-2012, 12:52 AM   #4
wildwizard
Member
 
Registered: Apr 2009
Location: Oz
Distribution: slackware64-14.0
Posts: 755

Rep: Reputation: 227Reputation: 227Reputation: 227
Quote:
Originally Posted by T3slider View Post
Are you using
Code:
#!/bin/sh
at the start of the script? I think parameter expansion like this may be a bashism...though I could be wrong.
Here is the list of everything that does change when you do (call it as sh) :-

http://www.gnu.org/software/bash/man...OSIX-Mode.html
 
Old 10-15-2012, 09:47 AM   #5
larryhaja
Member
 
Registered: Jul 2008
Distribution: Slackware 13.1
Posts: 293

Rep: Reputation: 76
Quote:
Originally Posted by waddles View Post
bash-4.1$ pknt=789 <-----added for interactive mode
bash-4.1$ jj="00000$pknt"
bash-4.1$ jj=`echo ${jj-3)}` <-----error??
bash-4.1$ echo $jj
789
I don't have a 13.37 computer to work with but it works on Slackware64 14.0 no matter what the shebang I use, as well as in interactive mode. I'm not sure why you would want to use the first echo statement. It is pretty much redundant in that usage.
 
Old 10-15-2012, 12:51 PM   #6
T3slider
Senior Member
 
Registered: Jul 2007
Distribution: Slackware64-14.1
Posts: 2,297

Rep: Reputation: 722Reputation: 722Reputation: 722Reputation: 722Reputation: 722Reputation: 722Reputation: 722
It also works on Slackware64-13.37 using /bin/sh and /bin/bash, but it does not work when using /bin/ash (or in interactive mode using ash). The link wildwizard posted mentions parameter expansion but not *which* uses are valid. Obviously bash doesn't discriminate, but other shells might (see `man ash`, which doesn't list
Code:
${parameter:offset}
as valid). I have no idea why it isn't working for you though, assuming /bin/sh is linked to /bin/bash.

Last edited by T3slider; 10-15-2012 at 12:53 PM.
 
Old 10-17-2012, 07:57 AM   #7
waddles
Member
 
Registered: Sep 2012
Posts: 372

Original Poster
Rep: Reputation: 1
String manipulation won't work in script but will if extracted

willysr, when I went to get that segment of the script I found a missing preceding "if"-- Dah! working too long
Apologies
 
  


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
[SOLVED] string manipulation in a script file mahmoodn Linux - General 12 06-02-2010 02:39 PM
String manipulation with BASH script King V Programming 9 04-21-2006 04:15 PM
firefox 1.05 binaries won't work when extracted MidniteHex Linux - Newbie 8 07-19-2005 02:50 AM
String manipulation with a script. philipina Programming 4 03-16-2004 03:42 PM
String manipulation with a script? philipina General 1 03-15-2004 01:07 PM


All times are GMT -5. The time now is 10:15 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration