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
Using last parameter within a script? sugarat Shell Programming and Scripting 5 03-22-2009 01:13 AM
passing parameter from Shell-script to Sql-script subodhbansal Shell Programming and Scripting 0 09-21-2007 06:15 AM
Parameter to script mahabunta Shell Programming and Scripting 2 02-13-2007 05:33 PM
Parameter from result of a script mgirinath UNIX for Dummies Questions & Answers 2 12-03-2005 03:28 AM
Pass Parameter to Another Script rvprod UNIX for Dummies Questions & Answers 4 04-05-2002 12:07 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-01-2008
Laibro Laibro is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 2
Parameter problem in my script

Hi all


I hope that any one help me with my small problem


My problem is:

inside my script their is a parameter x=example.tar.Z

I want to write a script to let y=example (without .tar.Z)


Thank you in advanced
  #2 (permalink)  
Old 06-01-2008
xxmenxx xxmenxx is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 12
Try this
Code:
x=example.tar.z
y=`echo $x |cut -f 1 -d . `
echo $y
  #3 (permalink)  
Old 06-01-2008
danmero danmero is online now Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,371
Useless use of echo and cut
Code:
x=example.tar.z
y=${x%.tar.z}
echo $y
  #4 (permalink)  
Old 06-01-2008
xxmenxx xxmenxx is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 12
danmero, can you explain your code please
what "%" means here??
thanks in advance
  #5 (permalink)  
Old 06-01-2008
danmero danmero is online now Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,371
You can retrieve (expand) variables value by enclosing the variable name in curly braces and preceding the left curly brace with a dollar sign, like that you eliminate the use of echo and backticks.
% will expand the variable removing the regexp(.tar.z) from the end of the variable value.

Regards,
  #6 (permalink)  
Old 06-01-2008
mschwage mschwage is offline
Registered User
  
 

Join Date: Jul 2005
Location: Oak Park, IL
Posts: 102
Two things to note:
  1. The ${var%pattern} construct is a ksh (and perhaps bash) shell thing, not bourne shell or csh.
  2. The thing on the righthandside of the % is a pattern, not a regexp.
See SH(1) USER COMMANDS SH(1), do a search in the page for a percent sign. It's only about the 2nd or third entry down; you should find information about using this construct fairly readily.
  #7 (permalink)  
Old 06-01-2008
danmero danmero is online now Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,371
Quote:
Originally Posted by mschwage View Post
The ${var%pattern} construct is a ksh (and perhaps bash) shell thing, not bourne shell or csh.
I use Bourne shell(/vin/sh)sh
Quote:
Originally Posted by mschwage View Post
[*]The thing on the righthandside of the % is a pattern, not a regexp.
Yes, however you can use regexp.
Code:
y=${x%.*.?}
Sponsored Links
Closed Thread

Bookmarks

Tags
linux, regex, regular expressions, solaris

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 12:32 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
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