## Shell Expansion Question

Shell Expansion Question
# 1
08-22-2011
Shell Expansion Question

hey all,

what does one # stand for?
what does two ## stand for?
what does % mean?
what does two signs %% mean?
what 1* means here?
what *1 means here?

I searched google but I got hard explanation and hard english.
I need someone to explain each command to me in easy words!

thanks.
 eawedat View Public Profile for eawedat Find all posts by eawedat
# 2
08-22-2011
Did you try the man page for ksh? (man ksh) The man page has the info that you are looking for. If you have additional questions, after reading the specific areas in the man page, one of us can help.
 g.pi View Public Profile for g.pi Find all posts by g.pi
# 3
08-22-2011
The specific section you're interested in is "parameter expansion". You should find it documented in the man page of any shell that supports those idioms.

Regards,
Alister
 alister View Public Profile for alister Find all posts by alister
# 4
08-22-2011
Quote:
Originally Posted by eawedat
hey all,

what does one # stand for?
what does two ## stand for?
what does % mean?
what does two signs %% mean?
what 1* means here?
what *1 means here?

I searched google but I got hard explanation and hard english.
I need someone to explain each command to me in easy words!

thanks.
\${X} is a variable in its full syntax

Quote:
what does one # stand for?
Mask a regular expression, taking the less greedy portion, starting from left to right.

e.i.
Match as less as possible, zero or more characters, followed by a literal '1'
In your case if x="a1 b1 c2 d2" it matches 'a','1' and stops, returning the remainder as the result. "b1 c2 d2"

Quote:
what does two ## stand for?
Mask a regular expression taking the most greedy portion starting from left to right
e.i
\${x##*1} -> match as much as it can. Returns remainder.
if x="a1 b1 c2 d2" then it eats 'a','1',' ','b','1' and stops.

Quote:
what does % mean?
Start from right to left matching as less as possible.
Quote:
what does two signs %% mean?
Start from right to left matching as much as possible
Quote:
what 1* means here?
Match a literal '1' followed by zero or more characters. (translates to nothing or everything else after a '1' included)
Quote:
what *1 means here?
Match zero or more characters followed by a literal '1'. (Translates to everything before a literal '1' or nothing plus '1')

Click me. Some examples half way of the article.
This User Gave Thanks to Aia For This Post:
 Aia View Public Profile for Aia Find all posts by Aia
# 5
08-22-2011
Quote:
Originally Posted by eawedat
I need someone to explain each command to me in easy words!
Sorry, I'm not the one however you can take a look at http://wiki.bash-hackers.org/syntax/pe
These 3 Users Gave Thanks to danmero For This Post:
 danmero View Public Profile for danmero Find all posts by danmero
# 6
08-25-2011
thank you very much Aia
sorry for the late...
thanks danmero

---------- Post updated at 12:02 PM ---------- Previous update was at 10:37 AM ----------

Do Expansion work with csh? because I tried they work only with bash
 eawedat View Public Profile for eawedat Find all posts by eawedat
# 7
08-25-2011
@eawedat: I don't know about csh. Most of it should also work in ksh.
This User Gave Thanks to g.pi For This Post:
 g.pi View Public Profile for g.pi Find all posts by g.pi

## Use parameter expansion over a parameter expansion in bash.

Hello All, Could you please do help me here as I would like to perform parameter expansion in shell over a parameter expansion. Let's say I have following variable. path="/var/talend/nat/cdc" Now to get only nat I could do following. path1="\${path%/*}" path1="\${path1##*/}" Here...

## Bash expansion

Hello. I cannot write a command without using eval. Any help is welcome Note 1 : What does the function SOMETHING has no importance. Note 2 : What does the command find has no importance. It is an expansion variable problem : where to put or or or anythings else What works (FILTRE_1...

## Shell variable expansion in awk

I want to split one file input.tab into two separate ones, odd lines to input_reads1.txt, even lines to input_reads2.txt for a serial of files with similar name pattern. Also I want to "match" input/output file names to keep consistency of file name: CSEL_02.0_input.tab CSEL_03.4_input.tab...

## Bash shell expansion help

This is what I have in my directory. \$ ls test1.txt test2.txt test3.txt test4.txt test5.txt test_script.sh This is what my shellscript looks like. #!/bin/bash for filename in /shell_expansion/*.txt; do for ((i=0; i<=3; i++)); do echo "\$filename" ...

## Expansion does not work

Hi, I'm trying to figure out whether some files exist. Locations of those file are stored in a plain text file called temp.txt in this way: All environment variables (\$LIB_HOME and \$ORACLE_HOME) have been set using export command. Then I do: while read line; do ] && echo "OK ==> \$line" ||...

## Expansion within cp

I have a bunch of files which I need to transfer to another location... and some of these I need to skip. For e.g. let us say the files are: cust_abc.dat cust_xyz.dat cust_def.dat and I only want to move the first two. I want to do something like: cp cust_.dat <target> ...

## Need to print the expansion of the found string (the expansion is beween two delimiters '-' , '||'

Hi , could anyone help me out with this problem. sample.txt has this content : u001- this is used for project1 || u002- this is used for p2|| not to be printed u003- this is used for project3 || u004- this is used for p4 || u005- this is used for project5 || u006- this is used for p6...

## sudo and expansion

Hi there, Can anyone explain me the following behavior? hfserver:~# ls -l /home/cronlogs/mysqldump* -rw-r--r-- 1 root root 10658464 2009-01-18 03:00 /home/cronlogs/mysqldump_20090118030002 -rw-r--r-- 1 root root 10651035 2009-01-19 03:00 /home/cronlogs/mysqldump_20090119030001 -rw-r--r-- 1...

## ~ expansion in printf

Hi, I have a script that at one point prints to a file as follows: printf -- \$2 > ~/.mydir/\$1 The idea is to print to a hidden directory .mydir in my home directory. I've already sanitized the inputs and \$1 is in the format path1/path2/filename and \$2 is some user input. When I run this...

## Linux Shell Question: how to print the shell script name ?

Suppose I have a script named "sc.sh" in the script how to print out its name "sc.sh"?