bash

Operations that can be performed on Bash shell variables

Hi, I've known several operations we can do to variables in shell, e.g: 1) "#" & "##" operation with ${var#pattern}, we remove "pattern" in the head of ${var}. "*" could be used in the pattern to match everything. And the difference between "#" and "##" is that, "##" will remove the longest match substring while "#" removes the shorte...

Run a Bash script as root with Objective-C / Cocoa

Given that there is a file called copystuff in the Resources folder in a an xCode project, and that file reads: #!/bin/sh cp -R /Users/someuser/Documents /Users/admin/Desktop And if this bit of code below is linked to a button in IB ... it will copy the /Users/someuser/Documents directory to /Users/admin when the button is pressed in ...

(python) issue bash commands from within python script (alla perl system($cmd))

Within a python script, I want to issue a command. In perl, I could define a command, save it as a variable (here, $cmd) then type system($cmd) and then the command is executed. How can i do that in python? ...

Bash: space in variable value later used as parameter

While writing a bash script to help creating polaroid thumbnail using Imagick's convert commmand. I encounter a problem. Although, I manage to work around with this (actually, because convert is flexible enough), I still want to know how to solve this without such specific workaround. So basically, the bash script will get a caption val...

How do you append to an already existing string?

I want append to a string so that every time I loop over it will add say "test" to the string. Like in PHP you would do: $teststr = "test1\n" $teststr .= "test2\n" echo = "$teststr" echos: test1 test2 But I need to do this in a shell script ...

Tab autocompletion in bash vi shell mode

When using MSYS on a windows platform, I "set -o vi" to use the vi shell mode. Tab autocompletion for files and directories stops working. How to I renable this while remaining in vi shell mode? ...

Pass email to a script : STDOUT question

I am catching emails to "script@localhost" with /etc/aliases: script: root,"|/path-to-my-script" this gets an email on STDIN and I am parsing and passing it to other scripts. #!/usr/bin/ruby email = ARGF.read ...parse...parse-some-more... system("/my-other-script.sh #{email.todo}") the question is - what would be a best way to ca...

BASH file attribute gymnastics: How do I easily get a file with full paths and privileges?

Dear Masters of The Command Line, I have a directory tree for which I want to generate a file that contains on two entries per line: full path for each file and the corresponding privileges of said file. For example, one line might contain: /v1.6.0.24/lib/mylib.jar -r-xr-xr-x The best way to generate the left hand column there appe...

ApacheBench result to a file

I would like to save ApacheBench (ab) tool on linux to a file. When I run it with -v 2 it displays some results in my ssh window. How to move these data into a file and make sure that it will not display on ssh no more? I've tried > file.txt but it does not work and still display data in my ssh window. ...

How do I set environment variable completion in a bash shell on mac

In a bash shell on linux, if I type: echo $DISP and hit tab, it completes to: echo $DISPLAY It doesn't work in bash on OSX 10.5, and I'm using the same .bashrc Is there a shell option or setting I can use to set this. ...

CVS branch name from tag name

I have a number of modules in CVS with different tags. How would I go about getting the name of the branch these tagged files exist on? I've tried checking out a file from the module using cvs co -r TAG and then doing cvs log but it appears to give me a list of all of the branches that the file exists on, rather than just a single branch...

Using sed to replace a string with the contents of a variable, even if it's an escape character.

I'm using sed -e "s/\*DIVIDER\*/$DIVIDER/g" to replace *DIVIDER* with a user-specified string, which is stored in $DIVIDER. The problem is that I want them to be able to specify escape characters as their divider, like \n or \t. When I try this, I just end up with the letter n or t, or so on. Does anyone have any ideas on how to do this...

uniq - skipping last N characters/fields when comparing lines

'man uniq' documents the -f=N and -s=N options which make uniq skip the first N fields/characters respectively when comparing lines, but how would you force uniq to skip the last N fields/characters? ...

running two bash commands simultaneously on two different computers from one script

I have a client and a host program (written in c) which I want to run from two different remote locations simultaneously. Since I have to do this some 50 times to gather data, I don't want to have to run them individually. On one side, I need to log in via ssh, start the script and tell it to write the output to a file. Then I need to...

Bash threading: wait for all job threads to finish doesn't work?

Hi, I'm writing a little script, that will create archives in main thread and after each archive is complete, a new thread would be created by calling function that would take care of uploading these archives. The reason I want uploading to be done in background is so that another archive could be created while the previous archives are ...

bash, numeric prefix for emacs bindings?

hello Is it possible to use emacs bindings in bash shell with numeric arguments, for example in emacs C-u 5 C-d deletes five characters. Is there an equivalent way of doing the same in bash prompt? Thanks ...

Replacing HTML ascii codes via a bash script?

Hello again! I need a way to replace HTML ascii codes like ! with their correct character in bash. Is there a utility I could run my output through to do this, or something along those lines? Thanks! ...

converting string to lower case in bash shell scripting

Hi, Is there a way in bash shell scripting so that I can convert a string into lower case string. For example, if $a = "Hi all" I want to convert it to $a = "hi all" Thanks a lot for your help ...

pipe bash output to two different streams

I have a bashscript that spawns processes on two different machines over ssh and then cat's the output of one into a text file. How can I have the output ALSO displayed in the terminal as it's running? ...

echo prints out -e inside script

when I run it in the terminal (bash) echo -e ."\c" prints out . and suppresses the newline. When I run the following script (all the code) echo -e ."\c" echo -e ."\c" it prints out .. and suppresses the newlines. when I run it inside a script with the shebang (!#/bin/sh), it prints out -e . -e . and suppresses the newline. Why? ...