bash

How to get a variable value if variable name is stores as string?

How can I retrieve the variable value if I have variable name as string? var1="this is the real value" a="var1" Do something to get value of var1 just using variable a. Thanks. So here is the actual problem: I have some AMI's (Amazon Machine Image) and I want to fire few instances of each AMI. As soon as booting is complete, I want to s...

How do i put stars into `read`?

Hello, what do i need to do for code in Bash, if i want to put stars, or even just that you cant see anything, when the user types something in using read. What do i need to do to edit read, so it can have like stars or so. ...

Find out if install script runs on mac or linux machine

Hi *, I'm trying to find out if my install scrip is running on a Mac or Linux device. Can someone give me a hint? Thanks Burntime ...

Autocomplete for the ruby command in bash

In the Bash shell, I would like to run a directory of ruby scripts from anywhere. Adding the directory to the $PATH doesn't do it. I want to type 'ruby,' start typing the first letters of a script name, and then press tab to autocomplete the script name. For instance, I'm in /~/username/foo/bar and want to run /~/ruby/test/script1.rb ...

Bash: controlling SSH

Hello, I have this bash file, which asks for IP, password, etc. for OpenSSH to a device. Now, if i use ssh root@ip, i have to enter the password. This is really irritating. Secondly; i cannot let my script send commands to it. This is what i want-> Not the password thing; i already found something; but it tells me the commands are n...

Have ruby Unit::Test speak the results of the test

I've been using the built-in OSX 'say' command to signal the end of long running tests. It's easy and convenient. I'd like to make it speak the last line of the results which says "6 tests, 18 assertions, 0 failures, 0 errors" but still keep the ongoing output. Any ideas how to do this? I've tried: ruby overlay_test.rb | tail -n 1 | ...

Sequence expression in bash

I'm used to used the following feature of bash : for i in ${1..23} ; do echo $i ; done This doesn't generalize. For instance, replacing 23 by even $p does not work. As the documentation says, this is a purely syntactic feature. What would you replace this with ? Note : Of course, this could be done using a while and an auxiliary var...

Bash syntax: What is the "<<"?

Could someone explain the "<<" in the following code? mysql test<<E0Q Select * from signins I'd try to search for it myself, but symbols are hard to search for... Thanks, Dan ...

Possible to use $1 within Bash array?

The script I'm writing will require me to pass some command line parameters. I would like to use these parameters within an array, but I'm not sure how. A very basic example of this would be (script run as ./script.sh array1): #!/bin/bash array1=( a b c d ) echo ${#$1[@]} The output should be 4, but I receive the following error: li...

Linux: How do I delegate exotic commandline arguments using a script?

Hello! I want to write a wrapper bash script, and to pass all arguments to a called program. I was very sure, that this works correctly: #!/bin/sh someProgam $@ But when passing exotic arguments (empty, unescaped, in quotes, ...) this fails. For example: without the wrapper script, someProgram "1 2" 3 results in the arguments [1 2] ...

Is there an "escape converter" for file and directory names available?

Hi script-writers, The day came when I had to write a BASH script that walks arbitrary directory trees and looks at arbitrary files and attempts to determine something regarding a comparison among them. I thought it would be a simple couple-of-hours_tops!_ process - Not So! My hangup is that sometimes some idiot -ahem!- excuse me, _lov...

Copy nested folders contents to one folder recursively (terminal)

I have a Wordpress upload folder that is structured using subfolders for months. wolfr2:uploads wolfr$ tree . . |-- 2007 | |-- 08 | | |-- beautifulkatamari.jpg | | |-- beautifulkatamari.thumbnail.jpg | | |-- beetle.jpg | | |-- beetle.thumbnail.jpg How do I use terminal to copy all the images recursively into another ...

How to reenter Vim after :! bash?

I'm slowing getting to know Vim and Bash shell scripting and am running into this issue: When I'm running MacVim, I sometimes want to use the command line to compile whatever it is I'm working on (in this case a small Java program). So I type :! bash and compile whatever it is that I need and test it. Then when I want to go back to the ...

The not-so-useless "yes" bash command: how to confirm a command in every loop

Hi all, I wrote a loop to unzip all zip files in a directory. for f in *zip do unzip $f done However, I have to confirm the overwrite at every step: replace file123.txt? [y]es, [n]o, [A]ll, [N]one, [r]ename: A How can I rewrite a loop to send at every cycle the same command? ...

redirecting standard output to the calling process

hello everyone Im no bash expert so bear with me I have a python script thats starting other processes, which then emit log messages on stdout. what bash command would I use to redirect stdout of those child processes back to the stdout of the parent process (the python script thats starting the processes)? thank you in advance ...

How to implement a timer keypress in bash?

Here's what will happen, a message is displayed with a specified time waiting for keypress, if no keypress then it will resume. Example "Press ESC to exit, otherwise you will die.. 3..2..1" "Press 'x' to procrastinate and check email, read some blogs, facebook, twitter.. otherwise you will resume work for 12 hours.. 3..2..1" This sho...

Little Bash Script: Catch Errors?

I've written (well, remixed to arrive at) this Bash script # pkill.sh trap onexit 1 2 3 15 ERR function onexit() { local exit_status=${1:-$?} echo Problem killing $kill_this exit $exit_status } export kill_this=$1 for X in `ps acx | grep -i $1 | awk {'print $1'}`; do kill $X; done it works fine but any errors are shown...

is there a scripting solution for determining the default application path for a file on the Mac?

For a given extension, for example ".psd", I'd like to be able to determine the default application path for opening this file, for example "/Applications/Adobe Photoshop CS4.app". I've looked into the Launch Services API, and there are clearly programmatic ways to get this information. Unfortunately for my particular scenario, only a ...

Bash: add value to array without specifying a key

Is there a way to do something like PHPs $array[] = 'foo'; in bash vs doing: array[0] = 'foo' array[1] = 'bar' ...

Linux bash: Multiple variable assignment

Does exist in linux bash something similar to the following code in PHP: list($var1, $var2, $var3) = function_that_returns_a_three_element_array() ; i.e. you assign in one sentence a corresponding value to 3 different variables. Let's say I have the bash function myBashFuntion that writes to stdout the string "qwert asdfg zxcvb". Is ...