Sponsored Content
Top Forums Shell Programming and Scripting Reading a string and passing passing arguments to a while loop Post 302590152 by agama on Saturday 14th of January 2012 11:04:29 AM
Old 01-14-2012
In your original example the variable i was assigned the whole record (e.g. val1:env1:opt1). In the code that zaxxon suggested, the components val1 env1 opt1 were broken out and assigned to variables A, B and C. There would be no need to reference i, as there wasn't anything assigned to i anyway. You should be able to use A, B, and C as is.

From your original post, you also do a lot of extra work to only read a subset of lines from the input file. That isn't handled by zaxxon's example. Moving along the same lines as was offered, the following code will generate just the lines between START and STOP (inclusive) and assign them to the variables f1, f2, and f3 (A, B, C).

Code:
awk -F : -v last=${STOP:-0} -v first=${START:-0} '
    /^#/ { next; }
    NR >= first && (last == 0  || NR <= last) {
        print $1, $2, $3, $0
    }

' input-file | while read f1 f2 f3 i
do
        echo "first field: $f1"
        echo "second field $f2"
        echo "third field $f3"
        echo "whole record (i) $i"
done

This User Gave Thanks to agama For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

passing arguments

I'm trying to pass a filename, or all the files in the current directory to the ls command with a script. Unsuccessful so far, here are a few of my attempts: #!/bin/ksh read fname #if (( $# > 0 )); then $fname | ls -l #fi this produces a long listing of all the files in my current... (4 Replies)
Discussion started by: jpprial
4 Replies

2. Shell Programming and Scripting

passing in arguments into a file using a loop

Hi, so Im a bit new to shell scripting and want to do the following but not sure how. Basically I have a file named "output" which contains misc text but inside the file I want to set up variables like $1 or some symbol. Anyways, in another file called "list" I have a list of items that I want to... (11 Replies)
Discussion started by: eltinator
11 Replies

3. Shell Programming and Scripting

Passing Arguments-Help

Hi, I have a script which adds the user credentials to an ldap server. Im passing the variables as below.. /path/my_script $uname $pwd $environ ${deposit} If i enter some special characters like ';' in $pwd, script returns an error which is set to display if the user enters... (5 Replies)
Discussion started by: Tuxidow
5 Replies

4. Shell Programming and Scripting

passing arguments

Hi I have a script to which I pass multiple arguments, for example lets say the script name is "abc". I run the script like ./abc def /file <directory location> In the above "def" is the first argument and "/file" is the second argument. I expect <directory location> that is passed after... (4 Replies)
Discussion started by: zmfcat1
4 Replies

5. Shell Programming and Scripting

Passing arguments to the subshell

I have a shell script which is invoked by passing an argument. The outer shell script calls another subshell and I want the argument passed down to flow down to the subshell. E.g Invoking a shell ======>> abc_refresh.ksh NM Below is the content of abc_refresh.ksh Value1=$1... (7 Replies)
Discussion started by: Mihirjani
7 Replies

6. UNIX for Dummies Questions & Answers

Passing arguments

I need to pass arguments to a shell script.My batch is calling some java program. ################# x=$1 y=$2 java -classpath program ################### if first parameter and second parameter is null then java -classpath program if first parameter is not null and second parameter is... (3 Replies)
Discussion started by: mnjx
3 Replies

7. Shell Programming and Scripting

Passing arguments to csh

I have noticed this thing using csh when passing arguments Suppose I call a csh script using ../Scripts/plot-model.csh -vmod="npt02-z30.vmod" -R="0/80/0/30" -c="0/4.5" -aspr="1:10" Somehow the " get removed when doing $argv ending up with -vmod=npt02-z30.vmod... (0 Replies)
Discussion started by: kristinu
0 Replies

8. Shell Programming and Scripting

Passing arguments that contain space

hi All, i am trying to pass arguments that contain space , value will be stored in variables to be used further in script , i went thru previous posting , still its not clear to how to implement for my case. passing 3 args test.sh it is 'fun to work in unix' inside shell ... (3 Replies)
Discussion started by: gvkk
3 Replies

9. Shell Programming and Scripting

Using here document when passing arguments

I have a script test.sh which reads various inputs from a user. #!/bin/ksh read x read y read z echo x: $x y: $y z: $z # read few more things again read a read b echo a: $a b: $b When i run this script as test.sh << EOF 1 2 EOF (3 Replies)
Discussion started by: ariesb2b
3 Replies

10. Shell Programming and Scripting

How to avoid "Too many arguments" error, when passing a long String literal as input to a command?

Hi, I am using awk here. Inside an awk script, I have a variable which contains a very long XML data in string format (500kb). I want to pass this data (as argument) to curl command using system function. But getting Too many arguments error due to length of string data(payloadBlock). I... (4 Replies)
Discussion started by: cool.aquarian
4 Replies
MOVIXMAKER-2(1) 					User Contributed Perl Documentation					   MOVIXMAKER-2(1)

NAME
MoviXMaker-2 - Easily create customized eMoviX/MoviX/MoviX2 disc images SYNOPSIS
movixmaker-2[.pl] [--version|--help] [--verbose] [--debug] [--nogui] [--nodelete] [--boot-help-lang=Language] [--menu-lang=Language] [--subtitleFonts=FontSet] [--tv-region=Region] [--remote=RemoteControl] [--keyboard=KbLayout] [--movix=MovixSrcDir] [-o=OutputFile] [-t=TempDir] [-b=BootLabel] [--loop=NbrOfLoops] [--random] [--nodma] [--eject] [--reboot] [--shut] [--extra-genisoimage-options="opt1 opt2 ..."] [--extra-mplayer-options="opt1 opt2 ..."] [--unwanted-mplayer-options="opt1 opt2 ..."] DESCRIPTION
MoviXMaker is a simple Perl command line utility or a GTK+-2/Gnome2/GladeXML interface to create customized eMoviX/MoviX/MoviX2 ISO files. It includes disk image customization possibilities such as : - boot help language, subtitle fontset, boot label selection. - you can specify [e]MoviX[2] parameters such as : movix/mplayer menu language (language), keyboard layout (kb), tv region (region), remote control (remote), loop, random, shutdown (shut), reboot, eject, dma, extra_mplayer_options and unwanted_mplayer_options. OPTIONS
All options that may be abbreviated to uniqueness can use a single dash. --version Displays MoviXMaker-2's version and exits. --help Display help messages [similar to this help] then exits. --verbose Verbose genisoimage output. --debug Debug mode (kind of movixmaker-2 verbose). --nogui Do not display the graphical interface. --nodelete Don't delete temporary directory. --boot-help-lang=Language Specify the language of the CD boot help messages. --menu-lang=Language Specify the MoviX/MPlayer menu language. --tv-region=Region Specify the tv region among: ntsc, ntsc-j, pal, pal-60, pal-nc, pal-m, pal-m60, pal-x, secam. --remote=Remote Specify the remote control among: hauppauge, haupserial, hauppauge2, logitech, pctv, abit, realmagic, grundig_tp720, kingman_code_026. --subtitleFonts=FontSet Specify which font set will be included in iso image. -k KbLayout, --keyboard=KbLayout Specify the keyboard layout to use. -m MovixSrcDir, --movixDir=MovixSrcDir Location of the *MoviX* directory. -o OutputFile, --output-file=OutputFile Name [with full path!] of the output iso image. -t TempDir, --tmpDir=TempDir Directory that will contain the temporary files. -b BootLabel, --boot-label=BootLabel Make *MoviX* boot with your favorite label (new default boot label). --loop=NbrOfLoops Don't delete temporary directory. --random Don't delete temporary directory. --nodma Make *MoviX* run with DMA turned off (fixes old-HDs issues). --eject Make *MoviX* eject the CD once it finished playing. --reboot Make *MoviX* reboot the PC once it finished playing. --shut Make *MoviX* poweroff the PC once it finished playing. --extra-genisoimage-options="opt1 opt2 ..." Extra options for genisoimage. --extra-mplayer-options="opt1 opt2 ..." Extra options for MPlayer. --unwanted-mplayer-options="opt1 opt2 ..." Options you want to be sure MPlayer will not use. AUTHOR
Pascal Giard, <evilynux@yahoo.com> COPYRIGHT
Copyright (C) 2003, 2004 Pascal Giard <evilynux@yahoo.com> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MER- CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. SEE ALSO
Gnome2(3), Gtk2(3), Getopt::Long(3), Config::IniFiles(3) perl v5.8.8 2007-09-02 MOVIXMAKER-2(1)
All times are GMT -4. The time now is 02:43 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy