By "within a loop" do you happen to mean "behind a pipe?" also known as "inside a subshell"? That will not work. Variables inside a subshell do not get communicated to outside the subshell.
In which case is there a possibility to evaluate the output of the command to another variable.
eg.
Last edited by rbatte1; 04-16-2019 at 06:04 AM..
Reason: Changed ICODE tags to CODE tags
Hi,
I am giving a grep command, and i am getting the output. i want to store it in a variable
for eg
a = grep '12345' /dir/1/2/log.txt ( the output is number)
b= grep 'basic' /dir/1/2/log1.txt (in this case the output is character)
so how to assign the output of grep to a variable
... (1 Reply)
Good day, everyone!
I've got a small problem with re-assigning the variable form the loop. What I'm trying to do is:
#!/bin/bash/
VAR1="AAA"
VAR2="BBB"
VAR3="CCC"
for WORD in VAR1 VAR2 VAR3;
do
$WORD="DDD"
echo $WORD
done
:o
That's the output and error messages:
-bash:... (2 Replies)
Hi
I am trying to write a function that needs to be able to assign the last run shell command to a variable. The actual command string itself not the exit code of the command.
I am using the bash command recall ability to do this as follows:
alias pb='ps | grep ash' ... (3 Replies)
Hi ,
I would like to assign command (with pipe) output to a variable. The code is as follows. The goal of the code is to get the last folder folder with a particular name pattern.
myDate=`ls | grep 2009 | tail -1`
echo "myDate=" $myDate
However, in the presence of the pipe, the code... (3 Replies)
greetings all,
I am have a heck of a time trying to accomplish a very simple thing. I have an array of "shortname<spaces>id" created from a dscl output. I want to assign shortname=word1 and id=word2. I have tried
shortname=$(${textArray} | awk '{print $1}') - and get 'awk : cannot open... (3 Replies)
Hi,
I've a requirement where I want to re-assign the value in the variable through which FOR LOOP loops.
For e.g.
Snippet of code
---------------
for i in $var
do
echo $i >> $tempFile
var=`echo $another_var | awk -F" " '{print $1}'`
done
I am re-assigning var so... (2 Replies)
Hi, wondering if it's been asked before but didn't find matches from google. Basically I have this line:
myvar=$(echo -e "a\tb")
Now somehow the '\t' from the echo output gets replaced with white space and then stored in $myvar.
It creates a problem for me later to use tab as delimiter to do... (2 Replies)
Code
set -x
STATUS="0"
echo $STATUS
for i in `ls -ltr Report*|awk '{ print $9 }'`
do
if
then
flg = "`head -1 "$i" |cut -c 31-33`"
echo `head -1 "$i" |cut -c 31-33`
echo $flg
if
then
echo "having Fun"
STATUS="2"
else
echo "no Fun"
fi
fi (2 Replies)
Hi
As bash does not support multidimensional arrays (?), I need some help with a problem. What I want to do is to assign variable names containing a counter in a loop .
what I want to do is basically something like this:
#!/bin/bash
for i in {1..8}; do
var$i = "some command"
done... (6 Replies)
Hi,
I am trying to get a loop counter i and set its value as the ouput of a command:
i=`printmo TEST1 | grep -i TEST2 | wc -l`
Then I want to use i as counter to run a loop i number of times.
Like if i gets a value of 5 I'll have to run loop 5 times.
But will i here be a numeric... (3 Replies)
Discussion started by: pat_pramod
3 Replies
LEARN ABOUT REDHAT
open
OPEN(1) Linux 1.x OPEN(1)NAME
open - start a program on a new virtual terminal (VT).
SYNOPSIS
open [-c vtnumber] [-s] [-u] [-l] [-v] [--] command command_options
DESCRIPTION
open will find the first available VT, and run on it the given command with the given command options, standard input, output and error are
directed to that terminal. The current search path ($PATH) is used to find the requested command. If no command is specified then the envi-
ronment variable $SHELL is used.
OPTIONS
-c vtnumber
Use the given VT number and not the first available. Note you must have write access to the supplied VT for this to work.
-s Switch to the new VT when starting the command. The VT of the new command will be made the new current VT.
-u Figure out the owner of the current VT, and run login as that user. Suitable to be called by init. Shouldn't be used with -c or -l.
-l Make the command a login shell. A - is prepended to the name of the command to be executed.
-v Be a bit more verbose.
-w wait for command to complete. If -w and -s are used together then open will switch back to the controlling terminal when the command
completes.
-- end of options to open.
NOTE
If open is compiled with a POSIX (Gnu) getopt() and you wish to set options to the command to be run, then you must supply the end of
options -- flag before the command.
EXAMPLES
open can be used to start a shell on the next free VT, by using the command:
open bash
To start the shell as a login shell, use:
open -l bash
To get a long listing you must supply the -- separator:
open -- ls -l
SEE ALSO login(1), doshell(8), switchto(1).
AUTHOR
Jon Tombs <jon@gtex02.us.es or jon@robots.ox.ac.uk>
-w idea from "sam".
19 Jul 1996 V1.4 OPEN(1)