I have a command in my shell script
CONFIGS="`tar -tzf ${CONFIGS_ARCHIVE}`"
CONFIGS_ARCHIVE is tar.gz file. If the command is executed what will be the value of CONFIGS?
Thanks,
LinuxPenseur
` quote is for executing the command. Unless you put that ` quote, shell will treat that command as a regular string.
If you want to execute a command and save it to a variable like you do, you must put that ` quote
Related
I have a shell script file in the rails application.Can anyone please tell me how can i call the shell script file with argument in my rails controller?
Thanks
Try backticks (``). For example a = `date` would assign shell's date command output to the a variable.
UPD: And you can obviously run something like `~/workspace/my_script.sh` to execute a script from a file, just make sure you give it executable permission first (with chmod +x ~/workspace/my_script.sh).
UPD2: And for the parameters, you can just interpolate them, like so `~/workspace/my_script.sh #{my_parameter_one}`. my_parameter_one will be available in the script as $1.
Sometimes it happens that a fastlane action throws an error like:
ERROR [2016-11-06 03:34:20.16]: Shell command exited with exit status 48 instead of 0.
I found troubleshooting difficult, as --verbose is not not verbose enough. By action I don't mean sh action, which is rather special case, but other fastlane actions e.g. create_keychain. The action create_keychain calls shell command security create-keychain and when it fails there is no clue what happened.
How do I find output of a shell command run by fastlane's action?
How do I find what shell command including all parameters is fastlane actually trying to run?
The output of the shell command is printed out by default when you use the sh action. Alternatively you can also run the shell command directly yourself using backticks (standard Ruby)
puts `ls`
The answer is that there is no such option at the moment, but it should be easy to add it.
I have created git issue #6878 for it.
I want to do the following commands in ruby.
ssh into another computer using ssh example#example
set source file source ~/.profile
cd to/some/folder
call my shell script with parameters, a json formatted string ,./my_script.sh my_hash.to_json
However I am facing these problems:
I call them in one line using backticks, it works, but it is a very bad practice in my opinion because it is not readable nor it is maintainable.
On the other hand, when I call my_hash.to_json, the resulted string has non-escaped double quotes, How do I escape them?
I would recommend to view this tutorial for ssh with ruby. then make a shell script and move it to server and then execute like a single command.
create a single shell script file for example script1 and then execute it at once instead of executing each command individually.
open file script1 using any editor.
copy all commands to script1 (each command in new line).
script1 file should look like this
#!/bin/bash
ssh example#example
source ~/.profile
cd to/some/folder
save file
make this file executable using chmod +x script
execute it in ruby like this [backtick]./script1[backtick]
note: copy script1 to usr/bin to avoid "./" and then try command only script1.
Reference for passing arguments in shell script is here.
I'm trying to make plink use the private key using the commnand line -i instead of relying on pagent in a ANT CVS task. I tried to set the cvsRsh param to "plink.exe -i my_private_key" without success. It complains that program cannot be found.
Of course i tried all sorts of quotes combination but it seems it tries to validate the path instead of just executing the cvsRsh variable.
So you have any ideas how to accomplish the same thing ?
This would be part of a reverse-engineering project.
To determine and document what a shell script (ksh, bash, sh) does, it is comfortable, if you have information about what other programs/scripts it calls.
How could one automate this task? Do you know any program or framework that can parse a shell script? This way for instance, I could recognize external command calls -- a step to the right direction.
For bash/sh/ksh, I think you can easily modify their source to log what has been executed. That would be a solution.
How about:
Get a list of distinct words in that script
Search $PATH to find a hit for each
?
bash -v script.sh ?
Bash's xtrace is your friend.
You can invoke it with:
set -x at the top of your script,
by calling your script with bash -x (or even bash --debugger -x),
or recursively by doing (set -x; export SHELLOPTS; your-script; )
If you can't actually run the script, try loading it into a text editor that supports syntax highlighting for Bash. It will color-code all of the text and should help indicate what is a reserved word, variable, external command, etc.