Signification of ## in line : device="${i##/sys/bolck/}" ???


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Signification of ## in line : device="${i##/sys/bolck/}" ???
# 1  
Old 04-09-2013
Signification of ## in line : device="${i##/sys/bolck/}" ???

Dear all,

I am trying to understand this script below:

Code:
#!/bin/bash

# can be executed as simple user?
for i in $(ls -ld /sys/block/?d? 2>/dev/null); do
device="${i##/sys/bolck/}"
DEVICELIST[$((count++))]="$device"
DEVICELIST[$((count++))]="$(cat $i/device/vendor 2>/dev/null) $(cat $i/device/model 2>/dev/null) ($(awk '{print ($1 / 2048) "MB"}' $i/size 2>/dev/null)"

done

dialog --menu "Available Devices:" 10 50 7 "${DEVICELIST[@]}" 2> choice.tmp

What are doing the double ## in line:
Code:
device="${i##/sys/bolck/}"

Many thanks for your help and kind regards,
freddie50
# 2  
Old 04-09-2013
Refer Parameter Substitution or Parameter Expansion in bash manual:
Code:
man bash

This User Gave Thanks to Yoda For This Post:
# 3  
Old 04-09-2013
It basically removes /sys/block/ and gives the device name alone

Code:
[root@Imperfecto_1 test]# echo $i
/sys/block/fd0
[root@Imperfecto_1 test]# echo ${i##/sys/block/}
fd0

Actually, you dont need ##, a single # will work in this case. ## is the longest possible match from the front and # is the shortest match from front.

Know the difference between # and ##
Code:
[root@Imperfecto_1 test]# echo $i
dev/sys/block/fd0
[root@Imperfecto_1 test]# echo ${i#*/}
sys/block/fd0                                                  
[root@Imperfecto_1 test]# echo ${i##*/}
fd0

HTH

--ahamed
This User Gave Thanks to ahamed101 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Howto auto boot SPARC | How to auto supply "start /SYS" and "start /SP/console" commands

When I power ON my T4-1, I got a prompt -> where I have to start /SYS and start /SP/console. How can I auto supply these two commands ? (3 Replies)
Discussion started by: z_haseeb
3 Replies

2. Shell Programming and Scripting

Failure: if grep "$Var" "$line" inside while read line loop

Hi everybody, I am new at Unix/Bourne shell scripting and with my youngest experiences, I will not become very old with it :o My code: #!/bin/sh set -e set -u export IFS= optl="Optl" LOCSTORCLI="/opt/lsi/storcli/storcli" ($LOCSTORCLI /c0 /vall show | grep RAID | cut -d " "... (5 Replies)
Discussion started by: Subsonic66
5 Replies

3. Shell Programming and Scripting

Delete all log files older than 10 day and whose first string of the first line is "MSH" or "<?xml"

Dear Ladies & Gents, I have a requirement to delete all the log files in /var/log/test directory that are older than 10 days and their first line begin with "MSH" or "<?xml" or "FHS". I've put together the following BASH script, but it's erroring out: for filename in $(find /var/log/test... (2 Replies)
Discussion started by: Hiroshi
2 Replies

4. Shell Programming and Scripting

Move a line containg "char" above line containing "xchar"

Okay, so I have a rather large text file and will have to process many more and this will save me hours of work. I'm not very good at scripting, so bear with me please. Working on Linux RHEL I've been able to filter and edit and clean up using sed, but I have a problem with moving lines. ... (9 Replies)
Discussion started by: rex007can
9 Replies

5. Shell Programming and Scripting

Find lines with "A" then change "E" to "X" same line

I have a bunch of random character lines like ABCEDFG. I want to find all lines with "A" and then change any "E" to "X" in the same line. ALL lines with "A" will have an "X" somewhere in it. I have tried sed awk and vi editor. I get close, not quite there. I know someone has already solved this... (10 Replies)
Discussion started by: nightwatchrenba
10 Replies

6. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

7. Emergency UNIX and Linux Support

Mapping between "Pseudo name" and "Logical device ID" in powerpath with SVM changed....

Dear All, I was having powerpath 5.2 on SUN server with SVM connected to CLARIION box.Please find the following output : root # powermt display dev=all Pseudo name=emcpower3a CLARiiON ID=CK200073400372 Logical device ID=60060160685D1E004DD97FB647BFDC11 state=alive; policy=CLAROpt;... (1 Reply)
Discussion started by: Reboot
1 Replies

8. Programming

could not open source file "sys/elf_386.h"

Hello All, i am porting my application from SunSolaris to Linux (RHEL4). When i compile my c/c++ code i am getting the following errors. 1. catastrophic error: could not open source file "sys/elf_386.h" #include <sys/elf_386.h> 2. catastrophic error: could not open source file... (2 Replies)
Discussion started by: tsaravanan
2 Replies

9. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies
Login or Register to Ask a Question