Try a slightly different example:
The variable expansion ${variable%pattern} expands the contents of variable removing the shortest string at the end of the contents that is matched by the filename matching pattern pattern.
The variable expansion ${variable%%pattern} expands the contents of variable removing the longest string at the end of the contents that is matched by the filename matching pattern pattern.
When you run the above commands with a ksh after setting the verbose and trace flags:
you will see output similar to:
When there aren't any special pattern matching characters in pattern (as occurred in your original example where pattern was .ksh, there is no difference between ${processname%%.*.ksh} and ${processname%.*.ksh}. When pattern doesn't match any characters at the end of the value of variable, the expansion behaves as if ${variable} had been specified (which is what happened in your example, since there was no .ksh at the end of the contents of your variable to be removed).
You can also use ${variable#pattern} and ${variable##pattern} to remove the shortest and longest, respectively, leading matching characters from the expansion.
This User Gave Thanks to Don Cragun For This Post:
A way to remember which end of the variable you are removing from is that for numbers, the % would be written at the end, so the end is removed.
The often misnamed octothorpe# is more usually referred to as a hash or wrongly as a pound (the pound is £) however if think that a currency amount of whole units is normally written as £12.34 or $12.34, or even €12.34 then the octothorpe (okay, I call it a hash too) trims from the beginning of the string.
I hope that this helps, but please forgive me being patriotic a pound being £, although I suppose in weight it's also lb so maybe I should just give up.
I have one script which consists of variables number of parameter and stuckup with following logic
case:1
script:
parameteres are
username,password,P1=v1,P2=v2,P3=v3
case:2
script:
parameteres are
username,password,P1=v1,P2=v2,P3=v3,P4=v4
i will pass username,password for all the... (6 Replies)
Hi AM Using Unix Aix
Used
${CMD} 2> ${ERR}
Dont get what above statement works .
SCRIPT=`basename $0`
ERR=$PWD/$SCRIPT.err
DATE=`date +"%d/%m/%Y"`
CMD=2
${CMD} 2> ${ERR}
if
then
echo "SUCCESS"
else
echo "FAILURE"
fi (1 Reply)
Hi All,
I have a file cleanlogs_imgp01_files which has the contents as follows,
cold_log|/opt/elf/cold_spool
get_orion_log|/opt/elf/logs
get_coldFiles_log|/opt/elf/logs
get_coldFiles_TuesToSat_log|/opt/elf/logs
get_coldFiles_MonToSat_log|/opt/elf/logs
And when i execute this, I get the... (1 Reply)
crw-rw-rw- 1 root root 1, 5 May 6 1998 /dev/zero
brw----rw- 1 root floppy 2, 28 May 6 1998 /dev/fd0H1440
In the above permission what is above C and B indicates?
Thanks (1 Reply)
Hi,
I am creating two shell scripts for Database backup and the output has to be routed to nohup.out file.
We will also be running the scripts in the background as
nohup.out <script_name> &
Do I manually need to create a nohup.out file in the directory from where the scripts are going... (1 Reply)
Hi, I am analisying an existing script. what the below code will do?
if
can some onle tell me what -a will do here. Upto my knowledge it can be used as and.
In this case they gave a comment like-- it will check for the existance of the ref file. I feel -f need to be used to check the existence.... (2 Replies)
:confused:
Hi All,
i am new to unix....so i am not sure whether i am asking the related question with our forum..
My question .....Can anyone explain me about the CGI script
is it something related to Unix or Linux or some other language.
Thanks in advance
Sha (1 Reply)
Hi ,
I need your help to know the exact operation of this following code ..
cat file1 | ux2dos | tr -d ''>>file2
file1 contains only one line : "DTS-PO\SPECTRUM WO 56"
the data contains a META CHAR "\" .. look at the above line.
But , The file2 output contains :... (7 Replies)
Hi All,
I am using Korn Shell HP UNIX and i am writing my scripts with filename extension as ksh or sh ..
I want to know what is the difference if i am giving ksh and sh
Other thing when we execute the shell script either we make it as executable and run directly else we give '.' or 'sh'... (2 Replies)