bash

How can I reverse the lines in a file?

I'd like to reverse the lines in a text file (or stdin), preserving the contents of each line. So, ie, starting with: foo bar baz I'd like to end up with baz bar foo Is there a standard unix commandline utility for this? ...

bash to beep if command takes more than 1 minute to finish

Hi, I'm looking for my bash to beep, if the command i execute take more than a certain wall time ( say 1 minute ). if it keeps on beeping every few minutes there after till i hit enter or something .. that's greate. Any clever ideas ? I can use screen's monitor function as last resort. (I'm on cygwin, but that shouldn't mat...

Need a way to gather total size of JAR files

I am new to more advanced bash commands. I need a way to count the size of external libraries in our codeline. There are a few main directories but I also have a spreadsheet with the actual locations of the libraries that need to be included. I have fiddled with find and du but it is unclear to me how to specify multiple locations. C...

How can you run AWK in a Bash script?

The problem is related to my answer here. I cannot get the following code to work #!/bin/bash wget http://www.google.com/coop/cse?cx=017685108214920485934%3Aizx6pzojwka -O CSE-spanien awk '/^searches [1-9]* sites, including:/ { print $2 }' CSE-spanien Example of the Error message [edited] $./code --2009-04-14 19:01:32-- http://www...

How can I use lame to encode wav files within a shell script?

I'm trying to set artist information via variables with spaces in them. Lame craps out. Maybe I'm being retarded with bash? #!/bin/bash year=2008; artist="New Kids On The Block"; album="The Block"; bitrate=320; lame="lame -b $bitrate --ta \"$artist\" --tl \"$album\" --ty $year" function first_half { for (( i=1;i<10;i++ )); do ...

Why the php code below is not returning the expected values?

I am trying to make a few php scripts that will run among other things system calls commands like top and other custom scripts. You can see the code below is super simple. The problem that we are having with the php below is that when I call the php from the linux prompt like: #php checkTOP.php it will return the top -n 1 output in ...

Pipe to/from Clipboard

Is it possible to pipe to/from the clipboard in bash? Whether it's piping to/from a device handle or using an auxiliary application, I can't find anything. For example, if /dev/clip was a device linking to the clipboard we could do: cat /dev/clip # dump the contents of the clipboard cat foo > /dev/clip # dump the contents of "f...

Suppressing "null device" output with R in batch mode

I have a number of bash scripts which invoke R scripts for plotting things. Something like: #!/bin/bash R --vanilla --slave <<RSCRIPT cat("Plotting $1 to $2\n") input <- read.table("$1") png("$2") plot(as.numeric(input[1,])) dev.off() RSCRIPT The problem is that despite --slave, the call to dev.off() prints the message null device ...

What's the best way to use R scripts on the command line?

It's very convenient to have R scripts for doing simple plots from the command line. However, running R from bash scripts is not convenient at all. The ideal might be something like #!/path/to/R ... or #!/usr/bin/env R ... but I haven't been able to make either of those work. Another option is keeping the scripts purely in R, e....

How can you open files which contain the word "exam" in terminal?

I want to open many pdf -files which contain the word exam. My Mac's terminal uses Bash. The word exam is randomly in the name: sometimes at the beginner, sometimes at the midlle and sometimes at the end of the name. How can you open files which contain the word "Exam" in terminal? ...

Run bash script as source without source command

Is there any way to mark a script to be "run as source" so you don't have to add the source or "." command to it every time? i.e., if I write a script called "sup", I'd like to call it as sup Argument rather than source sup Argument or . sup Argument Basically, I'm trying to use cd within a script. ...

How do I apply a shell command to many files in nested (and poorly escaped) subdirectories?

Hi! I'm trying to do something like the following: for file in `find . *.foo` do somecommand $file done But the command isn't working because $file is very odd. Because my directory tree has crappy file names (including spaces), I need to escape the find command. But none of the obvious escapes seem to work: -ls gives me the spa...

What does the command "cat /tmp/dir/:0" do?

When I did the command above, X11 opened. I am perplexed. Did I run it? How can I be sure that I do not run any program when looking at things? I really hate the idea that reading a text file may execute a program. How is it programmable possible to make programs that executes when running a simple cat-command, or similar command? ...

How do you use Binary conversion in Python/Bash/AWK?

I am new in binary conversion. I use Python, Bash and AWK daily. I would like to see binary conversion's applications in these languages. For example, I am interested in problems which you solve by it at your work. Where do you use binary conversion in Python/Bash/AWK? I would like to see examples of codes. ...

Multiple commands in an alias for bash

I'd like to define an alias that runs the following two commands consecutively. gnome-screensaver gnome-screensaver-command --lock Right now I've added alias lock='gnome-screensaver-command --lock' to my .bashrc but since I lock my workstation so often it would be easier to just type one command. ...

Limiting a script from sending alerts

I've got a bash script which detects a failed system component running on a unix box. The script sends out an email on failure. The script runs via run every minute (via cron). What's the easiest way to throttle sending the alerts to something like every 15 minutes? Could I create/update a file when I send an alert and only send the fil...

Stripping single and double quotes in a string using bash / standard Linux commands only

Hello Stack Overflow :-) I'm looking for something that will translate a string as follows, using only bash / standard Linux commands: Single-quotes surrounding a string should be removed Double-quotes surrounding a string should be removed Unquoted strings should remain the same Strings with unmatched surrounding quotes should remain...

Capistrano & Bash: ignore command exit status

I'm using Capistrano run a remote task. My task looks like this: task :my_task do run "my_command" end My problem is that if my_command has an exit status != 0, then Capistrano considers it failed and exits. How can I make capistrano keep going when exit when the exit status is not 0? I've changed my_command to my_command;echo and i...

Ruby on Rails: How can I specify runner script environment

I am using a shell script to run some runner scripts in my Ruby on Rails app. I need to run it on the production database, but the following: #!/bin/bash /usr/bin/ruby RAILS_ENV=production ../script/runner ../lib/tasks.rb gives an error: /usr/bin/ruby: No such file or directory -- RAILS_ENV=production (LoadError) I have tried to f...

Unable to make a tab completion file for MacPorts in Bash?

I did not find by Google a tab completion file for MacPorts. It should not apparetnly differ much from the ones for Git and Django. How can you make a tab completion for MacPorts in Bash? ...