Sponsored Content
Top Forums Shell Programming and Scripting Passing Shell variable from file to another command Post 302935482 by wisecracker on Tuesday 17th of February 2015 03:21:49 AM
Old 02-17-2015
Quick'n'dirty...
Eval is used so be aware!
Hardcoded as 6 variables for simplicity.
Longhand using OSX 10.7.5, default bash terminal.
Code:
#!/bin/bash
echo 'AAAA 111
BBBB 222
CCCC 333' > /tmp/text
count=0
text=( `cat /tmp/text` )
while [ $count -lt 6 ]
do
	eval var$count="${text[$count]}"
	count=$((count+1))
done
echo "$var0 $var1 $var2 $var3 $var4 $var5"

Results:-
Code:
Last login: Tue Feb 17 08:19:45 on ttys000
AMIGA:barrywalker~> cd Desktop/Code/Shell
AMIGA:barrywalker~/Desktop/Code/Shell> chmod 755 variables.sh
AMIGA:barrywalker~/Desktop/Code/Shell> ./variables.sh
AAAA 111 BBBB 222 CCCC 333
AMIGA:barrywalker~/Desktop/Code/Shell> _

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

passing value to shell variable

dear all How to passing the parameters or results to outside of the AWK program? anyone can help awk '{print $1}' file1 > $a ? (2 Replies)
Discussion started by: trynew
2 Replies

2. Shell Programming and Scripting

Passing shell variable to NAWK

I am trying to make a simple script in which i take input from shell and then forward the value to nawk (BEGIN). but when i run below mention script so it give no output. echo "Enter TRUNK GROUP:" read TGR cat /omp-data/logs/5etr/080422.APX | nawk -F"|" -v P=$TGR ' BEGIN { TG=P;... (1 Reply)
Discussion started by: wakhan
1 Replies

3. UNIX for Dummies Questions & Answers

Passing a command in a variable

I need to set up a strange system through which an arbitrary command is sent to a number of different servers (well, actually, VPS accounts). We have a command "vpass" that "passes" a command from the root level to resident VPS accounts. Suppose I wanted each VPS to do some trivial thing, like... (3 Replies)
Discussion started by: treesloth
3 Replies

4. Shell Programming and Scripting

Shell to Python variable passing

Hi, I had to create a new thread as the old thread had to much of confusion I have two files shashi.sh and py.py I want to pass a variable from shashi.sh to py.py. How do i achieve that ?. shashi.sh export X=12 echo "$("pwd")" echo "$X" exec python py.py "$(X)" py.py... (0 Replies)
Discussion started by: shashi792
0 Replies

5. UNIX for Dummies Questions & Answers

Passing a Shell Variable to awk

Hello, I have a file with 4 columns. An arbitrary example is shown below: a Tp 10 xyz b Tq 8 abc c Tp 99 pqr d Tp 44 rst e Tr 98 efg Based on the values in col 2 and col 3, I will execute another program. I have been running this:... (5 Replies)
Discussion started by: Gussifinknottle
5 Replies

6. Shell Programming and Scripting

Passing Variable Parameters (C shell)

I am trying to execute a copy command via shell script. However, on occassion, 2 or more files need to copied. How do I code for the multiple arguments? Does it matter how the files are delimited? Example: I have a script to copy files from 1 dir to another called duplicate.csh In most... (1 Reply)
Discussion started by: CKT_newbie88
1 Replies

7. Shell Programming and Scripting

Passing perl variable to shell command

Can we pass perl variable to shell commands. If yes, please give some example. (2 Replies)
Discussion started by: Anjan1
2 Replies

8. Shell Programming and Scripting

Passing a variable to kill command

I have a script that kicks off several processes in the background and stored their pids in a variable as follows: PID_DUMP_TRAN=$PID_DUMP_TRAN" "$! so I then have a list of pids If I echo $PID_DUMP_TRAN I get back a list of pids e.g. 8210 8211 8212 However I then want to kill all these... (5 Replies)
Discussion started by: sjmolloy
5 Replies

9. Shell Programming and Scripting

Passing a variable as input to another shell

I have a shell program that calls another shell program the following code works . chkTimeFormat.sh "10/9/12 17:51:19:783."|read c but when I am passing the the time in a variable like in the code below, the shell chkTimeFormat.sh is not returning proper value time="10/9/12... (9 Replies)
Discussion started by: swayam123
9 Replies

10. UNIX for Dummies Questions & Answers

Passing Shell Variable to awk

Hello All, May i please why my shell variable is not getting passed into awk script. #!/bin/bash -vx i="1EB07C50" /bin/awk -v ID="$i" '/ID/ {match($0,/ID/);print substr($0,RSTART,RLENGTH)}' /var/log/ScriptLogs/keys.13556.txt Thank you. (1 Reply)
Discussion started by: Ariean
1 Replies
CCCC(1) 						      General Commands Manual							   CCCC(1)

NAME
cccc - C and C++ Code Counter, a software metrics tool SYNOPSIS
cccc [options] file1.c ... DESCRIPTION
CCCC analyses and reports measurements of source code in C, C++, and Java. It was developed to augment programmers' instinctive applica- tion of numeric rules of thumb about what constitutes high or low quality products with an automated analysis tool. CCCC processes the files listed on its command line. If the filenames include '-', read a list of files from standard input. This program is work in progress and is not well documented. Please be prepared to refer to the source code for the meaning of some options. OPTIONS
--help Generate this help message. --outdir=dname Directory for generated files (default=.cccc). --html_outfile=fname Name of primary HTML report generated (default=outdir/cccc.html). --db_infile=fname Preload internal database from named file (default=no initial content). --db_outfile=fname Save internal database to named file (default=outdir/cccc.db). --opt_infile=fname Load options from named file (default=use compiled-in option values, refer to cccc_opt.cc for option information). --opt_outfile=fname Save options to named file (default=outdir/cccc.opt). --lang=string Use language specified for files specified after this option. Languages supported are c, c++, ada, and java (default=use lan- guage/extension mapping controlled by options). --report_mask=hex Control report content (refer to ccccmain.cc for mask values). --debug_mask=hex Control debug output content (refer to ccccmain.cc for mask values). AUTHOR
CCCC was written by Tim Littlefair <tim_littlefair@hotmail.com>. This manual page was written by Colin Watson <cjwatson@debian.org> for the Debian system (but may be used by others). CCCC(1)
All times are GMT -4. The time now is 07:34 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy