bash

How do I fix my Ruby installation

Hi all, I rather cleverly (or not in hindsight) installed RVM, which kept hanging whilst compiling Rubies. I have removed the .rvm directory but now my system has reverted to Ruby 1.8.7 i.e. when I type: ruby -v which ruby they both point to 1.8.7. How do I get the ruby command to point to my 1.9.1 installation, which is located in...

echo that outputs to stderr

Is there a standard bash tool that acts like echo but outputs to stderr rather than stdout? I know I can do echo foo 1>&2 but it's kinda ugly and, I suspect, error prone (e.g. more likely to get edited wrong when things change). ...

Help with variables and new lines, and quoting in a bash script

I would like to automate the following svn command. Note this command produces the desired results on my system - Ubuntu 10.04, svn 1.6.6, bash shell, when issued from the command line: svn ci -m $'Added new File: newFile.txt\nOrig loc: /etc/networking/newFile.txt' /home/user/svnDir/newFile.txt I would like to run that command in a ba...

Wrapping of comma separated data in bash to a fixed line length

Hi I would like to wrap the following comma separated data: -X, run, abs, absolute, accept, accept, alarm, schedule, atan2, arctangent, bind, binds, binmode, prepare, bless, create, caller, get, chdir, change, chmod, changes, chomp, remove, chop, remove, chown, change, chr, get, chroot, make, close, close, closedir, close, connect, conn...

Can I use what I wrote on the shell (bash, cmd, irb, etc) in a script automaticaly?

The general idea is pretty simple, I want to make a script for a certain task, I do it in the shell (any shell), and then I want to copy the commands I have used. If I copy all the stuff in the window, then I have a lot of stuff to delete and to correct. (and is not easy to copy from shell) Resume: I want to take all the things I wrote...

How do I logout from a computer using shell ?

How can I log out of my computer using shell such the log-in window appears again? I need this functionality in one my Linux script. Update: I want to replicate the code working behind the Logout button of my Ubuntu. Desktop Enviroment being used: GNOME ...

SVN Export Only Changed Files

I currently commit files to my SVN server (which is located on my web host), and from there I SSH in and export them to the working directory in my htdocs. As my application gets larger and larger, a full export is a waste of time. How can I only export the files that have been changed? svn export -r xxxx:HEAD http://svn/ Is a solut...

Shell Scripting For loop Syntax Error

Hello, I am trying to make a simple shell script to ping a source but I am getting bash-2.03$ ./test.sh google.com 10 .5 /home/users/me 16 256 ./test.sh: line 35: syntax error near unexpected token `((' ./test.sh: line 35: `for (( i = 1 ; i <= $totalArguments ; i++ ))' This is the code: #!/bin/bash ip=$1 count=$2 interval=$3 outputD...

Getting input in system() function (Mac)

#include <iostream> using namespace std; int main() { short int enterVal; cout << "enter a number to say: " << endl; cin >> enterVal; system("say "%d"") << enterVal; return 0; } Is what I am currently trying. I want the user to enter a number and the system() function says it basically. The code above has an erro...

Bash: how to simply parallelize tasks?

I'm writing a tiny script that calls the "PNGOUT" util on a few hundred PNG files. I simply did this: find $BASEDIR -iname "*png" -exec pngout {} \; And then I looked at my CPU monitor and noticed only one of the core was used, which is quite sad. In this day and age of dual, quad, octo and hexa (?) cores desktop, how do I simply pa...

How do you run multiple programs from a bash script?

I am trying to write a .sh file that runs many programs simultaneously I tried this prog1 prog2 But that runs prog1 then waits until prog1 ends and then starts prog2... So how can I run them in parallel? Thanks ...

recursive html2haml

I have many html files in nested directories which I need to convert to Haml templates I've modified the following bash script from here - http://terrbear.org/?p=277 to modify html files and not erb but I still need to modify it to be recursive ... #!/bin/bash if [ -z "$1" ]; then wdir="." else wdir=$1 fi for f in $( ls $wdir/*...

Bash: Nth word in a string

In bash, I want to get the Nth word of a string. For instance: STRING="one two three four" N=3 Result: "three" What bash command/script could do this? Thank you! ...

How to remove ˆM chars?

I have a file generated from windows that I have to paste into a script under linux. My script works fine, except for the fact that at the end of every line I got a ^M char. How can I remove it with bash? Currently my script is: #/bin/bash IFS=$'\n' for CUSTOMER in `cat exp.csv` do echo $CUSTOMER done ...

Prevent command "del /s" from entering a folder

I need to recursively remove unnecessary files from a svn repository and i have the following batch file to do this: @echo on del /s ~*.* del /s *.~* del /s Thumbs.db However, this is also deleting the entries under the .svn/ subfolders. Is there any way to prevent this commands from being executed under the .svn/ folders so that it d...

Make a Vim plugin that calls a bash script.

Sometimes I edit a file that represents a server restart. I would like to "bind" this restart to my vim session, so, after saving a file, it would call a bash script that would restart for me. For example, calling :wapache automatically calls restart_apache.sh somewhere in my machine. Is this possible? Is there a plugin that would orga...

What the difference between "$@" and "$*" in bash ?

Hello All, It seems to me that they both store all the command-line argument. So is there a difference between this two ? Thanks ...

removing a case clause: bash expansion in sed regexp: X='a\.b' ; Y=';;' sed -n '/${X}/,/${Y}/d'

I'm trying to remove a case clause from a bash script. The clause will vary, but will always have backslashes as part of the case-match string. I was trying sed but could use awk or a perl one-liner within the bash script. The target of the edit is straightforward, resembles: $cat t.sh case N in a\.b); #[..etc., varies] ;; ...

How do I convert filenames from unicode to ascii

I have a bunch of music files on a NTFS partition mounted on linux that have filenames with unicode characters. I'm having trouble writing a script to rename the files so that all of the file names use only ASCII characters. I think that using the iconv command should work, but I'm having trouble escaping the characters for the 'mv' com...

How to prevent code/option injection in a bash script

I have written a small bash script called "isinFile.sh" for checking if the first term given to the script can be found in the file "file.txt": #!/bin/bash FILE="file.txt" if [ `grep -w "$1" $FILE` ]; then echo "true" else echo "false" fi However, running the script like > ./isinFile.sh -x breaks the script, since -x is inter...