bash

Details of redirection in bash (Cygwin specifically)

I'm wondering if anyone can point me at resources dealing with the low(ish) level mechanics of how output rediction works in bash. Unfortunately, I've only been able to turn up pages and pages of the basic "> sends output to a file" guides, but nothing seems to go into more detail than that. In particular, I'm facing a strange situatio...

bash: defining a variable with or without export

What is export for? What is the difference between: export name=value and name=value ...

ImageMagick and Piping

I have the following commands that create a sprite containing a normal state and a hover state: convert -background none -pointsize 11 -fill white -size 100x -gravity NorthWest caption:'Test' top.png convert -background none -pointsize 11 -fill grey -size 100x -gravity SouthWest caption:'Test' bottom.png montage top.png bottom.png -geom...

bash script shell input

I am currently writing a bash script and when i run the useradd command it requires 2x input. What is the command to input from the bash script into the prompted password fields from useradd? ...

Bash redirection combined with "double pipe" notation

Is it possible to combine redirecting output to a file and pipes with ||? (Not sure what this is called) Example: (wget -qO- example.com/duff || exit) | some_processing >> outfile.txt If wget fails, I would like to exit and not run some_processing or create the blank file. ...

Recursively traverse Samba shares?

With bash on linux, how would I write a command to recursively traverse shares mounted, and run commands on each file, to get the file type and size, permissions etc, and then output all of this to a file? ...

What does ${2:-${1}} mean in Bash?

What does the following bash snippet do exactly? ${2:-${1}} ...

How can i use the wifi device connected through bash scripting?

How can i figure out if I have wifi devices connected to my PC thru bash scripting? * Is there anyway aside from 'iwconfig'? * If i have two devices connected and am using device A. Now if device A is down, then how can i setup to use device B instead? I'm just learning bash scripting, tutorials kinda confused me with all the new "co...

Sort subgroups of lines with command-line tools

Hi, I've been trying to find a way of sorting this with standard commandline tools, bash, awk, sort, whatever but can't find a way apart from using perl or similar. Any hint? Input data header1 3 2 5 1 header2 5 1 3 ..... ..... Output data header1 1 2 3 5 header2 1 .... Thanks ...

How to assign a heredoc value to a variable in Bash?

I have this multi-line string (quotes included) abc'asdf" $(dont-execute-this) foo"bar"'' How would I assign it to a variable using a heredoc in Bash? There is still no solution that preserves newlines. I don't want to escape the characters in the string, that would be annoying... ...

Touch files from Z->A with a delay

I need to do a touch of several files in a directory in reverse alphabetical order, with a 1 second delay. These files have spaces in their names. I've tried this: ls | sort -r | tr '\012' '\000' | xargs -0 touch and this: #!/bin/bash for i in $(ls -r); do touch "$i" sleep 1 done but the first makes it too quick and doesn...

How to pass long strings for search and replace in a bash, sed, or rpl script?

I am working to create a script which will take a string as an argument and replace recursively in a directory. The simple case (a single word) is admirably handled by the following find and replace script: grep -rl $1 . | xargs sed -i .backup -e "s/$1/$2/g" But here things get a bit more tricky. The string I am trying to deal with...

How can I write a shell-script that will email me a file if the file is not empty?

I'm looking for a script I can run to check if a text file is empty, if it is then do nothing but if it has something in it, I want it to send me an email with the text file as the message. No idea how to do it. ...

How to capture x screen using PHP, shell_exe and scrot

I'm building a web page screen capture application for an internal R&D project. Environment: Ubuntu 9.04 (default desktop install), Apache, PHP. So far I've got a bash script that takes one parameter (URL), fires up firefox, grabs the screen and saves it as a PNG. I've tried running this from terminal and it works fine. Here's the Bas...

git, capistrano and windows please help

hi I am trying to deploy my app to my server using capistrano I am in a Git Bash and have commited everything and setup deloy.rb file and remote repo on Github. Now when i try and cap command even cap -h from Git bash i get error : sh.exe": cap: command not found I am in the correct dir. It seems Git Bash is not linked to capistran...

Automatically timing every executed command and show in Bash prompt?

I often happen to forget to explicitly prefix executions with the "time" command, ideally I would see in the next shell prompt how much real time the last command took (on every command). I already scoured through the bash documentation, but couldn't find anything related. ...

How can I programmatically verify if a CYGWIN app is installed in a SH script ?

Here's the situation : I am writing a SH deployment script that will deploy a website with an RSYNC command in CYGWIN. After the installation, I want to send an e-mail to the development team to say that a deployment has been made with some details. I will use "exim" to send the mail from CYGWIN. The thing is that, exim is only optio...

How can you access the base filename of a file you are sourcing in Bash

I am sourcing a file in a bash terminal that needs to export some environment varibles. Example: source linux_x86.env the env file looks kinda like this: export ARCH=/home/user/project/linux_x86 I have a bunch of different architectures to compile for and I want be able to do something like this: export ARCH=/home/user/project/...

How do you use shell script variables as arguments to sed?

What I would like to do is something like the following: #!/bin/sh EMAIL="-e 's/SOMETHING//g'" somecommand | sed "$EMAIL" But I get the following: sed: -e expression #1, char 2: unknown command: `'' I've tried many variations. I know it just a matter of getting the string quoting right. The reason I'd like to do this is to break...

How to assign chdir to a variable in .bat?

I'm trying to translate a bash script into a .bat script. The specific line I'm tripping over is this: X=`pwd` What is the .bat equivalent? I need to take the directory that the script is currently running in as a variable so I can use a generic relative path to find files in the directory. I'm running on Windows-XP in the command ...