The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
How to delete trailing zeros from a variable Chandu2u Shell Programming and Scripting 16 05-09-2008 01:47 AM
dots and slashes DarkLord UNIX for Dummies Questions & Answers 1 01-27-2007 01:35 AM
spaces trimming while assigning to a variable Lokesha SUN Solaris 2 06-07-2006 02:09 AM
Strip leading and trailing spaces only in a shell variable with embedded spaces jerardfjay Shell Programming and Scripting 6 03-07-2005 02:24 PM
Password slashes. hellz UNIX for Dummies Questions & Answers 4 11-30-2001 11:42 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-08-2009
ricksj ricksj is offline
Registered User
  
 

Join Date: Dec 2008
Posts: 11
trimming trailing slashes in variable

I'm using this thread as an example, but can't seem to apply it to my situation.

I'm trying to strip the trailing slash (/) from an input argument. Here's a snippet of my command line input and the troublesome code:

Code:
$ script_name -s "../pathname/dir/"
snip 8< ...
while getopts :s: FLAGNAME
do
    case $FLAGNAME in
s) start_dir=$OPTARG
start_dir=`echo "${start_dir}" | sed ` s/[^\/]\/+$ //``
echo $start_dir # should be ../pathname/dir
;;
    h)  echo "Wrong syntax"
    exit 1
;;
done
I get an error s/[: not found
  #2 (permalink)  
Old 01-08-2009
npatwardhan npatwardhan is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 135
try removing the space after sed..
  #3 (permalink)  
Old 01-08-2009
npatwardhan npatwardhan is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 135
oh and it should be quotes not `..
so the sed statement would be
Code:
start_dir=`echo "${start_dir}" | sed ' s/[^\/]\/+$ //`'
  #4 (permalink)  
Old 01-08-2009
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
Code:
echo '../pathname/dir//' | sed 's#/*$##'
` != '
Code:
....
start_dir=`echo "${start_dir}" | sed 's#/*$##'`
....
  #5 (permalink)  
Old 01-08-2009
npatwardhan npatwardhan is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 135
oh yeah missed the first ` for the echo..thanks for pointing it out.
  #6 (permalink)  
Old 01-09-2009
ricksj ricksj is offline
Registered User
  
 

Join Date: Dec 2008
Posts: 11
Thanks for the responses.

I was able to get this to work with the desired results:
Code:
start_dir=`echo "${start_dir}" | sed -e "s/\/*$//" `
Closed Thread

Bookmarks

Tags
awk, awk trim, trim, trim awk

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 08:57 AM.


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