Red Hat / Fedora :: Assign A Variable To A Command?

Sep 10, 2010

I can print a specific line of a file with:$ sed -n '20p' myFileHow can I store it in a variable (in a shell script)?(I wasn't successful with "myVar=sed -n '20p' myFile" for example)

View 2 Replies


ADVERTISEMENT

Programming :: Bash Script: Assign Command Ouput To A Variable Without Executing It?

Feb 12, 2011

I'm trying to execute the following command within a bash script:

Code:
tac /var/log/system.log | head -1
The script I wrote is:

[code]...

View 1 Replies View Related

General :: Assign Local Variable Values To Global Variable?

Feb 17, 2011

how to assign a local variable value to a global variable....

View 2 Replies View Related

Programming :: Search Within A Variable And Assign The Results To A New Variable?

Apr 25, 2011

how I can search within a variable and assign the results to a new variable. I'll use the following as an example -

cars="Audi BMW Cadillac Chevy Dodge Ferrari Ford Mercedes"
list=`echo ${cars} | egrep -o '<A?+|<C+'`

with the echo command I get the following output assigned to list -

A
C
C

What I'd like to get for output is -

Audi
Cadillac
Chevy

how I could do this regardless of upper/lower case letters?

View 5 Replies View Related

Programming :: Assign Value Of C Variable To Shell Variable?

Apr 28, 2010

included shell script inside c program, and i wanted to assign the value of c variable to shell variable..Can any one please suggest me how to do it?

View 8 Replies View Related

General :: Assign A Variable To The Output Value Of A Program?

Feb 6, 2011

so i wrote myself a very simple hellworld program in c++

...the usual stuff
int main()
{

[code]...

View 3 Replies View Related

Fedora Servers :: Command Can Run In Terminal To Help Assign Permissions?

Jan 4, 2009

Im running samba on fedora core 7, im abit new to the server part of fedora, i set up samba and it runs well, only issue i have now is resolving permissions( User Rights)i have a shared folder which has alot of files and many subfolders in it, the files and folders in this shared foldr were copied from our old Novell Server through samba, i need to assign permissions to this folder where by a defined usergroup can have full read and write permissions to all the files and folders and sub-folders in the shared folder. i tried doing it in GUI but i realized there were over 1000 subfolders.is there a command i can run in the Terminal to help me assign the permissions?

View 1 Replies View Related

Debian Programming :: Assign Variable In Bash When Stdout Is Updated

Jan 17, 2014

I am writing a script that calls a program which writes a lot of lines to stdout continuosly. If the last line in stdout has some regex, THEN, certain variables are updated. My problem is that I don't know how to do that.

A simplified example would be (it's not my exact case, but it I write it here to clarify): suppose I issue a ping command (which writes output to stdout continuously). Every time that the response time is t=0.025 ms, THEN, VARIABLE1=(column1 of that line) and VARIABLE2=(column2 of that line).

I think the following code would work in awk (however, I want the variables in bash and I don't know how to export them)

Code: Select allping localhost |awk '{ if ( $8 == "time=0.025" ) var1=$1 var2=$2}'

In the previous code, awk analyzes each line of the output of the ping command as soon as it is created, so the variables $var1, $var2, ... are updated at the appropriate time. But I need the "real-time" updated values of $var1, $var2 in bash, for later use in the script.

View 7 Replies View Related

Programming :: Bash Scripting...read A Value From A File Then Assign To Variable?

Feb 27, 2011

At my wit's end I can't find anything that I understand well enough to use. This is for a Unix class, we are working with shell scripting. File1 has 5 in it and File2 has 100 in it.The teacher wants us to read the values then do the math. This is what I have so far:#!/bin/bashvar1='cat File1'var2='cat File2'var3=`echo "scale=4; $var1 / $var2" | bc`echo The final result is: $var3

View 9 Replies View Related

General :: Assign An "here Documents" Section To A Variable In Bash?

Mar 11, 2011

Is it possible to assign an "here documents" section to a variable in bash?I would like to assign the following to a variable:

Code:
<html>
<body>
<p>THis is a test</p>
</body>
</html>

View 4 Replies View Related

Fedora :: Adding Variable Command Line Parameters To Desktop Launchers?

Mar 15, 2010

I have added an application launcher to my desktop and it works fine. However, I want to be able to feed parameters to the launcher before I launch the application. So, for instance, if the command is normally "/usr/bin/foo something" I want to be able to add the "something" parameter dynamically after clicking the launcher but before the application launches. Is this possible in Fedora?

View 2 Replies View Related

Debian :: Assign 775 To All The Files Using One Command?

Sep 22, 2010

is there anyother way of creating an user without the support of graphical or command base. one more question is what is the syntax to assign using chmod to a directory consisting of n number of files at atime in one single syntax suppose i want to assign 775 to all the files using one command

View 2 Replies View Related

Programming :: Calling Command From History Using Variable Like !$command?

Nov 19, 2008

suppose i store the history number of a command say :

1004 cat file

Then now i want to run it like : !1004 but by using a variable.

command=1004
!$command

i am getting errors like :

command=1004command

View 2 Replies View Related

General :: Assign A Different Command To Headphone's Button?

Jan 13, 2011

I bought a Media-Teach NEMESIS USB headphones. They work really great except there's this one button that lunches Windows Media Player on Windows but on Linux... it doesn't seem to do anything... So my question is, how do I assign a different task for this button on Linux? For example I want it to go to a website address.I guess I need to get what signal it sends thru usb to my system and then somehow manipulate it? Can this be done with a shell script or perhaps there's a tool/program available on Linux for this

View 2 Replies View Related

General :: Assign IP Address Using Command Line?

Mar 26, 2010

I am using internet in my home PC using Red Hat 9. To assign static IP to my linux machine I use "System Settings....> Network" and then double click on "eth0" to assign the static IP.Well these all settings by using GUI interface.Kindly guide me that if I use only command line interface "runlevel 1" then in that case which file should i edit and assign my static IP,Subnet Mask,Default Gateway DNS settings.2- 2nd thing is,is there any way that I may open web broswer in command line? or the administrator should only use internet on Run Level 5 ?

View 14 Replies View Related

Programming :: Using Variable In A Command?

Apr 14, 2011

i'm trying to execute a shell script, i'm trying to use the values in an array for use in a sed command:

sed -n '/Sales ID: ${array[$i]}/,/Totals:/p'

that command creates empty files. so my guess is that its not recognizing the array as an array but as text?
how would i be able to utilize the array in the command? i got it, didnt think that if i doubled up the single quotes that it would work, but this worked:

sed -n '/Sales ID: '${array[$i]'}/,/Totals:/p'

View 4 Replies View Related

Software :: Scripting : Using A Variable In A Command?

Jan 13, 2009

I need to create a zip file of jpg and bmp files. The zip file is named after the first file it finds which ends with .dat. Here is my script:

Code:

DAT_FILE= `find . -maxdepth 1 -iname "*.dat" | head -1 | sed 's/..(.*)..../1/'`
(cd pics; find . ( -name "*.bmp" -o -name "*.jpg" ) -print | zip ../$DAT_FILE -@ )

BTW my sed command cut off the first two chars and last four chars since find will return the filename is the form of "./filename.dat" and I just want to extract filename. When I run this script, it creates a zip file named ".zip". How do I fix this so the zip file is named after my dat file?

View 3 Replies View Related

Programming :: Store A Command In A Variable?

Jan 28, 2010

Code:

ls Again the command can be stored in a variable and then executed. Like

Code:

var=ls
&var

The above two codes are the same. The problem occurs when we try to pipeline it. Consider the following problem:

Code:

ls | grep *

works fine...but when we try to store it in a variable and run the command there is an error.

Code:

var="ls|grep *"
$var

how to store this kind of commands in a variable?

View 11 Replies View Related

SUSE :: How To Fix $PATH Variable - Command Not Found

Dec 20, 2010

I tried to install JRE to my remote Suse 11 SP1 linux.After i finished with files i typed like

export PATH=<my jre path>

now i have no bash commands - typing ls causes

-bash: ls: command not found

i think that i should re-export my PATH to the right value but i don't know what it should be. I tried differend values

/etc/profile
/usr/bin

View 3 Replies View Related

General :: Better To Use 'at' Command Instead Of Time Variable In Shutdown?

Apr 20, 2010

I was reading that if I want to do a one time scheduled command, I should use at, which I've never done, as opposed to cron, which i'm kinda familiar with. But what I want to do is reboot my server at 3am tomorrow and force it to check the file systems with a shutdown -rF. For this do I even need to use "at" or could I just say shutdown -rF 3:00.Will that also know that I mean 3am tomorrow and not say in 3 minutes from now or 3pm?

View 14 Replies View Related

General :: Any Way To Store Output Of Command Into Variable?

Mar 3, 2010

I tried using the tail command in my shell script and storing that value in a variable a but an error keeps coming. Is there any other way to store the output of a command into a variable. Cannot Read text from text file and store it in a variable using shell script. The thing is I need a number from the file new.txt and use that number in my script

#!/bin/bash
a = `tail -1 new.txt|head -n 1`
echo $a

View 2 Replies View Related

General :: Store Result Of Wc -l Command In Variable?

Apr 19, 2011

I want to store the result of wc -l as a variable so I can use it later in my script...so far unsuccessfully.

I have tried this:

set `echo awk '{ print $1, $6}' | wc -l` | echo $1

but it is far from working.

View 11 Replies View Related

Software :: How To Express Built-In Variable, RS In Awk Command

Apr 26, 2011

I am going to separate records with the string, "[J.System Info]" in awk command.

Both of the following expressions don't work well.

Code:
RS = "[J.System Info]"
(or)
RS = "[J.System Info]"

View 1 Replies View Related

Programming :: Change Variable In Case Command?

Aug 7, 2010

I want to display 4 options using the case command and refresh the screen when options 1 and 2 are chosen (no changes to the options and you get asked again to chose option), but give a message for option 3 and exit on option 4. I set this up with the script below, but choosing option 1 works and choosing option 2 exits the script.

Code:

#!/bin/bash
#testing options
Option="0"

[code]....

View 7 Replies View Related

Programming :: Pass A Shell Variable To An AWK Command?

Dec 23, 2010

I have the following code :

Code:
E_BADARGS=65
if [ $# -ne 2 ] ; then

[code]...

View 1 Replies View Related

Ubuntu :: Variable In A Script Error (command Not Found)?

Jan 13, 2010

I have the following script:

Code:
#!/bin/bash
for HOSTS in server01 server02 server03
do
echo "Connecting to $HOSTS"
echo "Resetting Password"
echo ""

[Code]...

done When I run the script I get an error message on the hosts that says: pass=test command not found. Any ideas why is not taking it as a variable?

View 1 Replies View Related

Programming :: Assigning Bash Variable With The System Command In Awk?

Mar 1, 2011

I am having all sorts of trouble trying to assign a variable within an awk script with the system command. I know there is a lot of ways around this problem, but for efficiency reasons, I would like to, within my awk script, do something like

system(x=3)

or

system(x=NR)

and, latter on the shell script which calls the awk script, use the variable $x. But nothing is passed to x. I have already tried things like

command = "x=3"
system(command)

and also used a pipeline within the system to pipe it to /bin/sh In fact tried a lot of stuff like that, using $(( )) etc etc etc I can create directories e write to files (yes, i could write to a file and read from there, but I dont think it is efficient, plus I am puzzled).

View 7 Replies View Related

General :: Simple Bash Command Causing Bad Variable Name

Feb 18, 2010

When I run this command from shell, it runs ok
export REVS=`svn info svn+ssh://svn.myone.ca/var/svn/story/trunk/lib |grep 'Last Changed Rev:'| awk -F: '{print $2}'`
However when I save it into a file called test.sh (of course, I chmod it with +x), I got error "export: 2: bad variable name"

Here is the file:
#!/bin/bash
export REVS=`svn info svn+ssh://svn.myone.ca/var/svn/story/trunk/lib |grep 'Last Changed Rev:'| awk -F: '{print $2}'`
I am using ubuntu.

View 7 Replies View Related

General :: Does The Output Of The Previous Command Get Stored In Any Variable

Mar 26, 2011

For example, when using bash you can use

Code:

to execute the previous command or

Code:

!<number> to execute the Nth command(use history to see the list). Or you can use

Code:

cd !-2:1

to cd into the value in the first field that was executed 2 commands ago Anyhow, say I run a command and the output is a path. Any way to cd and then some variable where OUTPUT of the previous command was stored? A variable that always stores the OUTPUT of the last command.

View 8 Replies View Related

General :: Environmental Variable In Bash Command String?

Feb 9, 2011

I do this:

Code:

a@b:~$ export A=hi
a@b:~$ echo $A
hi
a@b:~$ bash -c "export A=blah; echo $A"
hi
a@b:~$

Why doesn't the bash command print the new value of $A? Is there a way to make it do so?

View 6 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved