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


ADVERTISEMENT

Programming :: Calling A System Command In Perl?

May 20, 2010

I'm trying to call a system command in perl and am having an issue with it.

Here's an example of a command i'd like to call: Code: sed -i '4 c192.168.1.4 www.something.com' hosts this is the section in my perl script where I create the variable and call it: Code: $doit = `sed -i '$line c$ip $host hosts'`system($doit); The $line, $ip, and $host variables are working fine becasue I can replace that section with "prints" and they come out fine. I imagine the problem is where I am creating the $doit variable.

View 7 Replies View Related

Programming :: Less Doesn't Save Command History

Aug 13, 2010

less doesn't save command history, i.e. file .lesshst isn't created. If I create it manually, nothing writes to it too.OS AIX 5.3 I think linux users can have the same issue, hardly this issue depends on OS.

View 9 Replies View Related

General :: Bash Command History Update Before Execution Of Command

Jun 7, 2010

Bash's command history is great, especially it is useful when adding the history -a command to the COMMAND_PROMPT.However, I'm wondering if there is a way to log the commands to a file as soon as the Return key is pressed, e.g. before starting the command and not on completion of the command (using the COMMAND_PROMPT option would save the command once the prompt is there again).

I read about auditing programs like snoopy and session recorder like script but I thought they're already too complex for the simple question I have. I guess that deactivating that script logs all the output of the command would lead already in the right direction but isn't there a quicker way to solve that probelm?

View 1 Replies View Related

Software :: Command To Get History Command Lines And Time In SUSE?

Jun 23, 2009

I have to trace back what command and when it is used for the last 3 months. It is quite urgent as I have trouble with the system configuration.

View 5 Replies View Related

General :: Command To Delete Bash Command History?

May 31, 2010

What's the command to delete bash command history?

View 4 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

General :: Use 'history' Command To Fire Last Run Command?

Oct 14, 2010

How do I use the "history" command to fire the last run command?

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

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

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

Programming :: Put A Variable In The $PS1 Prompt That Will Change Each Time A Command Is Run?

Feb 11, 2011

I would like to put a variable in the $PS1 prompt that will change each time a command is run. I want the color of the $PS1 prompt to change each time a command is run.I know that I can do this:

Code:
PS1="h@w # "
## "#" is changes every time a command is run

[code]....

View 9 Replies View Related

Programming :: Receive Command Output And Store It To A Variable?

Apr 3, 2010

Suppose I want to account number of files beginning with abc , I can use "ls 'abc* | grep abc | wc -l", this will return me a number.
I want to store this number in a variable, say var1, so I tried
1. "ls 'abc* | grep abc | wc -l |read var1", but this didn't work as var1 has no value somehow.
2. var1='ls 'abc* | grep abc | wc -l', this just assign the entire string "ls 'abc* | grep abc | wc -l" to var1, which is not I wanted.

I don't want to store the value to a temporary file and then read the value from that file. I think there should be a direct way to get the value, but don't know how. I know in tcsh, one can just use set var1='ls 'abc* | grep abc | wc -l', but it also doesn't work in bash. Can anyone give any clue about this?

View 5 Replies View Related

Programming :: Pass An Expect Command Result Into A Variable And Then Use It Again?

May 4, 2010

I'm trying to create a program that would locate the oldest file of a certain type on a server. Here's the commands:

OLDEST_PATH=`find -L / -depth -maxdepth 6 -mindepth 6 -type d | sort -f | head -1`
OLDEST_FILE=`find -L $OLDEST_PATH | grep .mp3 | sort -f | head -1`
ls -al $OLDEST_FILE

I'm writing this all in expect but I'm having problems. The main problem I have is whenever I try to run the first command, I can't seem to isolate the result of the OLDEST_PATH so that the 2nd command will work. There always seems to be a newline in the variable and the result is only "find -L" command running and it bypasses the variable. If I can just figure out how to get the 1st and 2nd command to work, then I can figure out the 3rd. Here's some code:

Code:
send "find -L / -depth -maxdepth 6 -mindepth 6 -type d | sort -f | head -1
"
sleep 20
expect -re "(.*)

[Code]....

I know there is a better way to write this. I've tried multiple ways and this just happens to be the last way I've tried it. If you try running this, you'll notice that there is still carriage returns after the result of OLDEST_PATH and it prevents the 2nd "find" command from working properly.

View 2 Replies View Related

Programming :: Using Variable To Store Command Lines In A Pipeline?

Jan 28, 2010

Was trying to write a shell script that has if conditional statements to decide different arguments for a command.Basically:

Code:
if [ "$1" = 1 ]
then

[code]...

View 6 Replies View Related

Programming :: Variable Substitution In Sqlite Open Db Command?

Jun 15, 2010

I have the following TCL code:

if{ [catch {sqlite3 db /path/to/db/file} result] } {
puts stderr $result
} else {
do something
}

What I want is to use a variable for the file name/path. When I put in a variable instead of the absolute path, I get an error: "missing close-brace: possible unbalanced brace in comment while executing"

This is weird because when I run the code with the fully qualified pathname, it works fine. I substitute out the pathname for a variable containing the pathname ($variable) and I get this error.

View 1 Replies View Related

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

Programming :: Calling A Script From Another Script - Command Not Found

Mar 25, 2010

I'm trying to call a shell script from within another scipt, but returns with a `command not found` error msg.

script_name=$1
./$script_name &; exit 0

I think its something to no with the "./" bit. i also tried

"./"$script_name &; and
"./$script_name" &

no luck.

View 3 Replies View Related

Programming :: Bash - Calling A Specific Variable Based On User Input?

May 3, 2011

I'm trying to call a specific variable based on a user selection. For example:

Code: Select a file:

[1] foo.tar
[2] bar.tar

Enter a selection: I have already coded each possible selection to have its own variable. If the user selects 2 I need to select $SELECTED_TAR2, or if they select 1 I need to select $SELECTED_TAR1 and then do something like this behind the scenes:

Code: cp /home/user/$SELECTED_TAR2 /home/user/backup/$SELECTED_TAR2

I was thinking something like this:

Code: echo "Enter a selection: "
read -e SELECTED_NUMBER
cp /home/user/$SELECTED_TAR$SELECTED_NUMBER /home/user/backup

[code]....

View 2 Replies View Related

General :: Use "history" Command To Fire Last Run Command?

Oct 7, 2010

How do I use the "history" command to fire the last run command?

View 4 Replies View Related

Programming :: Storing Output Of "time" Command To A Variable

Jan 21, 2011

In my script, I need to get execution time of a command (say 'ls') in mili seconds level. For this i tried using "time" command to retrieve the total execution time in milli seconds. But, the problem is that, how to save the output of time command in a variable. The format of the command is like "time ls -R /opt" Going further, the o/p of 'time' command is:

real 0m0.003s
user 0m0.004s
sys 0m0.000s

Here, in my script, I would like to use only middle line "user 0m0.004s" saved to the variable but unable to find out the way.

View 1 Replies View Related

Programming :: Calling Bash Script With More Than One Variable From Python Script?

Oct 4, 2010

I am calling a bash shell script from a python script trying to pass several arguments to the bash script with no succes can this be done? I have researched (google) with no clear indication of how to achieve this. Using "os.system"

View 4 Replies View Related

Fedora :: How To Know Command History Of All Users?

Jul 7, 2010

I am trying to find a method or tool to know the exact command history of all my users.I have tried to use "psacct" ,but it is not solving my perpous as it is only giving the command name.means let say 10 users have used "rm" command to remove 10 differint files then I want to know which user has removed what file.

But psacct will only give me the command name like rm used bu the user name.Then I tried to use the "w: command but it is also not solving the problem..

View 6 Replies View Related

Fedora :: Reset The History Of The Command At?

Dec 12, 2010

How can I reset the history of the command at? The system labels each command starting with 1, is there a ay to reset that back to 1.

View 2 Replies View Related

General :: Find Out PID Of A Command Which Is In History?

Jun 20, 2011

If someone has done something wrong on a shared linux machine. If i want to find out who is that person or ip from where it is been done what are all the possible ways. 1 possibility I thought was to get the PID of the command and get other details from that PID?

View 4 Replies View Related

General :: Can Not Use Command 'history' In Fedora13?

Nov 1, 2010

Just as the subject,I didn't find a appropriate answer with google. Is there any command to replace it?

View 5 Replies View Related

Server :: How To Save Command History

Jun 20, 2010

how to save command out put to another file. Ex: #ps -ef that particular cmd output i need to save another file. is it possible And how to save command history in Linux.

View 1 Replies View Related

Ubuntu :: Preserve The Command History In/for Zsh After Boot?

May 9, 2010

How can I preserve the command history in/for Zsh after boot?

View 2 Replies View Related

Ubuntu :: Directory History Displayed After Each Use Of 'cd' Command / Why Is So?

Jun 15, 2010

Can someone explain why my directory history is being displayed after each use of the 'cd' command. After about an hour the list is filling up my window.

View 6 Replies View Related







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