| | |
Help!need Help reading the bash script
Please support our Shell Scripting advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: May 2007
Posts: 7
Reputation:
Solved Threads: 0
Hi..
im a newbie in shell scripting, and also new in this forum..
i understand the command below is just reading from /etc/passwd
and getting whatever in field 1 and 3 (which are username and userID)
after the cut the format will be
username:uid
my guess,its making the array with the index in respect to its userID
but i dont understand the expression
{i#*:}]=${i%: *}
could somebody please explain how to read those...
and what those will evaluate to...
and how to work with things like those(i dont think those're regex-i have no clue)..
=========================================================
for i in $(cut -f 1,3 -d: /etc/passwd) ; do array[${i#*:}]=${i%: *}done
im a newbie in shell scripting, and also new in this forum..
i understand the command below is just reading from /etc/passwd
and getting whatever in field 1 and 3 (which are username and userID)
after the cut the format will be
username:uid
my guess,its making the array with the index in respect to its userID
but i dont understand the expression
{i#*:}]=${i%: *}
could somebody please explain how to read those...
and what those will evaluate to...
and how to work with things like those(i dont think those're regex-i have no clue)..
=========================================================
for i in $(cut -f 1,3 -d: /etc/passwd) ; do array[${i#*:}]=${i%: *}done
•
•
Join Date: May 2004
Posts: 178
Reputation:
Solved Threads: 10
Shell Scripting Syntax (Toggle Plain Text)
for i in $(cut -f 1,3 -d: /etc/passwd) do echo "${i#*:}" "${i%:*}" done
This lets you see what is going on.
Shell Scripting Syntax (Toggle Plain Text)
${i#*:}
Shell Scripting Syntax (Toggle Plain Text)
${i%:*}
arr[number] = name
Shell Scripting Syntax (Toggle Plain Text)
${i%:*}
Shell Scripting Syntax (Toggle Plain Text)
${i%: *}
Try man (or info) for bash or ksh. This is called parameter substitution using a POSIX shell. It finds substrings.
Last edited by jim mcnamara; May 29th, 2007 at 1:00 pm.
•
•
Join Date: Apr 2006
Posts: 148
Reputation:
Solved Threads: 40
bash's parameter substitution is a good feature to have, but it has ugly syntax. for what you want to do, you can use awk
Shell Scripting Syntax (Toggle Plain Text)
awk -F":" '{print $3,$1}' /etc/passwd
![]() |
Similar Threads
- how to recursive search of subdiretories in BASH script (Shell Scripting)
- Bash Mail script help (Shell Scripting)
- HELP! Who can solve this bash script? (Shell Scripting)
- web page statistics - my first bash script (Shell Scripting)
Other Threads in the Shell Scripting Forum
- Previous Thread: help... for LINUX/UNIX users only
- Next Thread: Swaping Files
| Thread Tools | Search this Thread |





