The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Error: `mv olddir/ newdir/ ` never works on new version of bash? meili100 UNIX for Dummies Questions & Answers 5 02-20-2008 04:56 PM
Works from bash prompt, but not from script! siegfried Shell Programming and Scripting 7 02-10-2008 02:56 PM
Substring in Shell Script smartbuddy UNIX for Dummies Questions & Answers 3 08-17-2007 10:26 AM
Using variable with cp command in bash shell maheshsri Shell Programming and Scripting 4 12-04-2006 01:30 PM
command for CPU online/offline status in bash shell sars UNIX for Advanced & Expert Users 5 11-30-2006 06:10 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-27-2007
edwardtk11 edwardtk11 is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 2
substring command works but only in BASH shell

I am having trouble running a .sh file. The code 'x=${file_name:0:$z-11}' is giving me a bad substitution error. However when I run in BASH it works. Thing is when this goes to production the .sh will not be running in BASH. Is there a way to substring a string not in BASH or a way to invoke BASH and still run the .sh without any pauses. Thanks!

file_name="12366293address.txt"

#Grabs length of file_name string
z=${#file_name}

#Substrings file_name
x=${file_name:0:$z-11}
  #2 (permalink)  
Old 06-27-2007
Shell_Life's Avatar
Shell_Life Shell_Life is offline
Registered User
  
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
Edward,
A quick solution is to place the first line in the shell:

Code:
#!/bin/bash

Try first:

Code:
which bash

  #3 (permalink)  
Old 06-27-2007
edwardtk11 edwardtk11 is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 2
Thanks!!!!

works great!! Thanks!!!!
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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




All times are GMT -4. The time now is 01:06 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0