![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Basic bash 'for loop' usage | Orange Stripes | Shell Programming and Scripting | 2 | 12-18-2007 05:58 PM |
| Basic OS question | catwomen | HP-UX | 4 | 09-08-2006 05:39 PM |
| basic question | karthikosu | SUN Solaris | 2 | 07-12-2006 12:07 PM |
| basic question | urwannabefriend | UNIX for Dummies Questions & Answers | 1 | 04-10-2004 02:21 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
A basic question of FOR loop
Hi,
have a basic query. Please see the below code: list="one two three" for var in $list ; do echo $var list="nolist" Done Wht if I want to print only first/ last line in the list Eg one & three Regards er_ashu |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
awk
don't know if it is the best way but awk will work....
echo $variable | awk '{print $1,$NF}' note $NF represents the no of fields |
|
#3
|
||||
|
||||
|
with zsh and array:
Code:
zsh 4.3.4%zsh 4.3.4% list=(one two three) zsh 4.3.4% print $list[1] one zsh 4.3.4% print $list[-1] three Code:
$ list="one two three"
$ printf "${list%% *}\n"
one
$ printf "${list##* }\n"
three
|
|
#4
|
|||
|
|||
|
with bash
Code:
# var=(one two three)
# echo ${var[0]}
one
# echo ${var[2]}
three
|
|||
| Google The UNIX and Linux Forums |