Sponsored Content
Top Forums Shell Programming and Scripting puting arguments into varables Post 302196249 by sam4now on Saturday 17th of May 2008 10:34:46 AM
Old 05-17-2008
puting arguments into varables

hello all
I am written a script that would put a line of text and a file into two different varables for later use, i.e a script called pimp with any number of words and a filename which is the last argument.

so for eg $pimp my name is the name given to me when i was born Afile
where pimp is the script name
"my name ...... born" is the line of text
and Afile is a name of the file.


I can get the filename since is the last argument but how can i get the remaining argument


this is what i have done.
for arg in "$@"
do
: # nothing
done
echo "the last command line argument is $arg"
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Arguments

Ok so i had to create a file and put some random text into it which i did. THen u make a script which takes 2 arguments. The first being a line of text, the second being your newly created file. The script should take the first argument and insert it into the very top (the first line) of... (1 Reply)
Discussion started by: iago
1 Replies

2. Shell Programming and Scripting

[: too many arguments

Hi Guys I have this small Bash script - but it fails when I'm trying to run it. ./test.sh: && ; then # date >> /writable/sys/shutdown.log shutdown -h "now" exit fi done (4 Replies)
Discussion started by: tainted2real
4 Replies

3. Shell Programming and Scripting

Help puting background process ID's into an array

I am trying to write a script that runs another script consecutively and records the PID of the called script each time it runs in an array. I put in an echo statement to check the PID, when the script runs no PID is output, and the array seems to be empty. I assume it is problem with my code,... (3 Replies)
Discussion started by: Breakology
3 Replies

4. Shell Programming and Scripting

while puting shell variable in mysql command value does not interpolate

port=$(ssh tms6@$x cat /tms6/scripts/start.lc.sh | grep -P '^\/tms6\/bin\/lc' | cut -d' ' -f3 | cut -b 3-6) tpsip=$(ssh tms6@$x cat /tms6/scripts/start.lc.sh | grep -P '^\/tms6\/bin\/lc' | cut -d' ' -f4 | cut -b 9-) # IFS="\n" set -- $port ... (1 Reply)
Discussion started by: rrd1986
1 Replies

5. Shell Programming and Scripting

grep with two arguments to arguments to surch for

Hello, is it possible to give grep two documents to surche for? like grep "test" /home/one.txt AND /home/two.txt ? thanks (1 Reply)
Discussion started by: Cybertron
1 Replies

6. Shell Programming and Scripting

: [: too many arguments in for -f in if

Hi Experts , I have following code if ; then mv path /filename newdirpath echo "K* files moved successfully to newdirpath \n" else echo "K* files DID NOT moved successfully to newdirpath \n" fi I am getting "echo "K* files DID NOT moved successfully to newdirpath \n"... (19 Replies)
Discussion started by: ajaypatil_am
19 Replies

7. Shell Programming and Scripting

For f in * -- too many arguments

Hi guys, I am trying to make a script that will archive all the folders (except NOARCHIVE folder) and then remove those folders: cd my_specific_folder; for f in *; do if ; then tar czf $f.tar.gz $f && rm -r $f; fi; done && echo "All the folders within my_specific_folder are... (3 Replies)
Discussion started by: emanresu
3 Replies

8. Ubuntu

Sudo commands without puting in .bashrc

dear all, When I start my laptop, I need to run one command /etc/init.open-afs start and it require sudo privilege. The only solution which occur to me is to put this command in .bashrc. But then the trouble comes as everytime I open any new tab it ask for the sudo password, which is pretty... (5 Replies)
Discussion started by: emily
5 Replies

9. Shell Programming and Scripting

Too many arguments

because it gives me this error if? while read linea do #echo "Archivos Entrada: $linea" largo=`awk '{print length($linea)}'` echo "largo : $largo " if ; then #Here's the problem, I take this line and it works echo "a es igual a 1" fi... (3 Replies)
Discussion started by: tricampeon81
3 Replies
eval(3tcl)						       Tcl Built-In Commands							eval(3tcl)

__________________________________________________________________________________________________________________________________________________

NAME
eval - Evaluate a Tcl script SYNOPSIS
eval arg ?arg ...? _________________________________________________________________ DESCRIPTION
Eval takes one or more arguments, which together comprise a Tcl script containing one or more commands. Eval concatenates all its argu- ments in the same fashion as the concat command, passes the concatenated string to the Tcl interpreter recursively, and returns the result of that evaluation (or any error generated by it). Note that the list command quotes sequences of words in such a way that they are not further expanded by the eval command. EXAMPLES
Often, it is useful to store a fragment of a script in a variable and execute it later on with extra values appended. This technique is used in a number of places throughout the Tcl core (e.g. in fcopy, lsort and trace command callbacks). This example shows how to do this using core Tcl commands: set script { puts "logging now" lappend $myCurrentLogVar } set myCurrentLogVar log1 # Set up a switch of logging variable part way through! after 20000 set myCurrentLogVar log2 for {set i 0} {$i<10} {incr i} { # Introduce a random delay after [expr {int(5000 * rand())}] update ;# Check for the asynch log switch eval $script $i [clock clicks] } Note that in the most common case (where the script fragment is actually just a list of words forming a command prefix), it is better to | use {*}$script when doing this sort of invocation pattern. It is less general than the eval command, and hence easier to make robust in | practice. The following procedure acts in a way that is analogous to the lappend command, except it inserts the argument values at the start of the list in the variable: proc lprepend {varName args} { upvar 1 $varName var # Ensure that the variable exists and contains a list lappend var # Now we insert all the arguments in one go set var [eval [list linsert $var 0] $args] } However, the last line would now normally be written without eval, like this: | set var [linsert $var 0 {*}$args] | SEE ALSO
catch(3tcl), concat(3tcl), error(3tcl), interp(3tcl), list(3tcl), namespace(3tcl), subst(3tcl), tclvars(3tcl), uplevel(3tcl) KEYWORDS
concatenate, evaluate, script Tcl eval(3tcl)
All times are GMT -4. The time now is 06:23 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy