Parameter problem in my script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Parameter problem in my script
# 1  
Old 06-01-2008
Parameter problem in my script

Hi all


I hope that any one help me with my small problem Smilie


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 Smilie
# 2  
Old 06-01-2008
Try this
Code:
x=example.tar.z
y=`echo $x |cut -f 1 -d . `
echo $y

# 3  
Old 06-01-2008
Useless use of echo and cut Smilie
Code:
x=example.tar.z
y=${x%.tar.z}
echo $y

# 4  
Old 06-01-2008
danmero, can you explain your code please
what "%" means here??
thanks in advance
# 5  
Old 06-01-2008
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  
Old 06-01-2008
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  
Old 06-01-2008
Quote:
Originally Posted by mschwage
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
[*]The thing on the righthandside of the % is a pattern, not a regexp.
Yes, however you can use regexp.
Code:
y=${x%.*.?}

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Call Script with Parameter (that has another parameter)

Hi. How do I achieve this sh /EDWH-DMT02/script/MISC/exec_sql.sh "@/EDWH-DMT02/script/others/CSM_CKC/Complete_List.sql ${file_name}" Complete_List.txt The /EDWH-DMT02/script/MISC/exec_sql.sh has two parameters and it's working fine with this sh /EDWH-DMT02/script/MISC/exec_sql.sh... (7 Replies)
Discussion started by: aimy
7 Replies

2. UNIX for Dummies Questions & Answers

Passing shell script parameter value to awk command in side the script

I have a shell script (.sh) and I want to pass a parameter value to the awk command but I am getting exception, please assist. diff=$1$2.diff id=$2 new=new_$diff echo "My id is $1" echo "I want to sync for user account $id" ##awk command I am using is as below cat $diff |... (1 Reply)
Discussion started by: Sarita Behera
1 Replies

3. Post Here to Contact Site Administrators and Moderators

Unable to pass shell script parameter value to awk command in side the same script

Variable I have in my shell script diff=$1$2.diff id=$2 new=new_$diff echo "My id is $1" echo "I want to sync for user account $id" ##awk command I am using is as below cat $diff | awk -F'~' ''$2 == "$id"' {print $0}' > $new I could see value of $id is not passing to the awk... (0 Replies)
Discussion started by: Ashunayak
0 Replies

4. Shell Programming and Scripting

Passing parameter to script, and split the parameter

i am passing input parameter 'one_two' to the script , the script output should display the result as below one_1two one_2two one_3two if then echo " Usage : <$0> <DATABASE> " exit 0 else for DB in 1 2 3 do DBname=`$DATABASE | awk -F "_" '{print $1_${DB}_$2}` done fi (5 Replies)
Discussion started by: only4satish
5 Replies

5. Programming

Problem with STL's std::set container parameter to the operator << ()

Hi, I have this following code which gives me error when compiling. The problem is happening at the point where I create a const_iterator inside the overloaded insertion operator (i.e) operator << () function. The template argument version of set is not correct I guess. Could anyone please pitch... (3 Replies)
Discussion started by: royalibrahim
3 Replies

6. AIX

Audit problem : A system call received a parameter that is not valid.

while i try to start the audit i have the below error message . audit>audit start ** auditing enabled already A system call received a parameter that is not valid. please advice (6 Replies)
Discussion started by: thecobra151
6 Replies

7. Shell Programming and Scripting

parameter identification problem

Hello everyone suppose i have a script which can take any no. of parameters and in any order then how can i identify a particular parameter at which position it is entered suppose i call a script with four parameter ./abc.sh a b c d in above calling a is called at no. 1... (3 Replies)
Discussion started by: aishsimplesweet
3 Replies

8. Shell Programming and Scripting

Parameter Passing problem

Hi All, I developed a KSH script which will accept two parameters as input. These two parameters are some directories paths. In the script i am validating the number of paramaters it received as below #-------------------------------------- # Check Command line arguments... (8 Replies)
Discussion started by: Raamc
8 Replies

9. Shell Programming and Scripting

Problem if parameter has space in it using loop

for cmdopts in $*;do case $cmdopts in -mode) mode="$2";shift 2 ;; -server) server="$2";shift 2 ;; -Id) Id="$2";shift 2 ;; -passwd) passwd="$2";shift 2 ;; -rmtDir) rmtDir="$2";shift 2 ;; -lcDir) ... (9 Replies)
Discussion started by: pinnacle
9 Replies

10. Shell Programming and Scripting

Parameter Problem With an Array Variable

Hi, I have two bash shell scripts: test: rrdhcp78-120:test_data msb65$ cat ~/bin/test #!/bin/sh array1=() echo 'elements in array1:' ${#array1} ~/bin/test2 $array1 test2: rrdhcp78-120:test_data msb65$ cat ~/bin/test2 #!/bin/sh array2=${1} (5 Replies)
Discussion started by: msb65
5 Replies
Login or Register to Ask a Question