Ubuntu :: BASH Quote - Calling Commands Stored In A Variable?
Feb 19, 2010
I am having some weird problems with calling commands stored in a variable (I need to do this to assemble a command with a bunch of parameters automatically and then execute it).Example code that will replicate the weirdness:
What happens to the quotes? I have tried various combinations of single quotes, escaped quotes, etc, but it seems like quotes in a variable are not evaluated as quotes when that variable is executed.
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:
run_repeatedly "programX -o "./messy/path/output-$NUM.txt"" The echo inside the loop prints "...-$NUM.txt"; obviously I'm aiming to have bash substitute the iteration number so that I end up with many output files not 1.
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"
In linux how do I to get the ascii decimal/hex/oct code from a char or a ascii char from a decimal/hex/oct code. I see from the gnu sed user manual that I can use the d# o# x# to specify a character but I am not sure how to use that. If some one has a better way to get the the ` and ' chars through I want to sed with the backtick '`' character and ''' single quote character.
There is probably a very simple fix, but its wrecking my buzzI call the following on the command lineR CMD BATCH '--args Y_filename="one.txt" out="two.txt"' brew.RI want to call this from a bash script but replace one.txt with $1, and two.txt with $2 (ie the first two arguments from the command line)I have tried in vane"R CMD BATCH '--args Y_filename="$1" out="$2"' brew.R"
I have a script1.sh (see code below) which calls another script (which is a sort of template -> template.sh). But when i call template.sh i need to send an argument with it.
echo "$VAR files which are older than 1 hour in folder $dirpath" exit $exitstatus I geuss the command should look like something like this command
Code:
./script1.sh -d /
You don't have to look at the code of template.sh, thats not important. I just need to know how i get this to work I don't think it's that hard, but i just can't see it ...
On one of my servers I see this when I log in. What does this mean and how can I get it to go away? Everything seems to work fine, but none of my other machines give this error.
I'm trying to read content of file to variable and use this variable in for loop. The problem is, when I have c++ comment style in file - /*. Spaces in line are also interpreted as separated lines.
For example:
Code:
Changing $files to "$files" eliminate these problems but causes that whole content of variable is treated as one string (one execution of loop).
!<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.
I would like to call some firefox macros from bash so that I can manipulate them in some scripts. Does anyone know how to do that?Currently I'm using the imacros firefox add-in
I have a bash script that changes the iptables.Now i call this bash script in my php code.When this bash script is running the part of code that contains iptables instruction is not running because we need to be in superuser mode(root)
Now in my bash script, I want to get the output /home/user instead of $HOME once read. So far, I have managed to get the $HOME variable but I can't get it to echo the variable. All I get is the output $HOME.
I have a bash profile (with custom terminal color settings) and also a gnome panel (with quick-launchers on it and other customizations). Assuming these things are stored in text files, where in my ~home directory can I find them? I ask because I want to duplicate them on a another linux box to have the same bash profile/taskbar, and If I can do it by copying files instead of manually recreating them, it would be better.
Most all of this works when I execute it manually, but I cannot figure out how to get a bash script to execute it automatically.In this particular case, I am trying to build the xorg utilities. If I manually step through the process, prepending the commands with CFLAGS, LDFLAGS, etc, all of the packages build.So I created a bash script, test.sh:
I would like to access/print a C Variable of any type "as it is stored in the memory". I would expect the output to be an array of bits. Whats the simplest/shortest way to do that?
I'm trying to write a python script that will use the current user's name when interacting. Ex: when started, it should say "hello daweefolk" when I am logged in. I've tried Code: username=os.system("echo $USER") but the variable remains empty. What is the correct code?
I'm making a script I want to be able to just call (ie, rclick instead of ./rclick) where do I put it?
~/bin? /bin? /usr/bin?
Also, how do I pass a variable to the script (rclick 10 will rightclick 10 times) (Found, so simple... $1)Lastly, can I force it to run on CPU2? CPU1 is completley locked up if I run this on it... Or can I make it use less cpu cycles?
What happens when the script executes is that the ssh connection works and parks me at the remote hosts's shell login. Therefore, the "firefox" command refuses to execute. I need to know how to make the "ssh" connection occur, stay open, and go into the background so that the rest of the script can execute.If I could also do this with the "firefox" line so that the entire term window could be closed would also be helpful.
Code: #!/bin/bash f1=apple f2=banana f3=grape echo "Enter number 1,2 or 3:" # 3 is entered read x choice=${f+$x} # yielding choice=$f3 echo "$choice" # so $choice is, essentially, read as f3, which = grape
grape I am, essentially, trying to combine "f" and the number entered (3, for example) to create "f3", which when echoed as "$choice" will lead to grape!
I am trying to call a script say mkdir.sh into another script that will make use of the dir's which are created in the first script. I know that I could code it all together, but I am trying to avoid rewriting the mkdir script as it is long.
I would like to be able to connect to a machine, list a directory, wait long enough for me to see the results then move on to the next machine.This is failing:
I googled and tried to find an easy step by step-by-step guide on how to use a bash script read a variable from a file. This is the way I did it (but it does not really work so something is wrong, but what?) (testfil2 contains one line that readsidnumber=1578
I have machine that I used to VNC to on my network with Remote Desktop Viewer from my Fedora 12. When I first connected I checked the checkbox that I wanted to store the pw. Now the pw on the other machine has changed but Remote Desktop Viewer does not ask for a new password, it just gives me a black screen, like I am connected but I can't see anything. I'd like to know if anyone knows where this pw data is stored on the system so I can start fresh. I already tried uninstalling Remote Desktop Viewer and installing it again.