bash

How can I detect dos line breaks in a file?

I have a bunch of files. Some are unix line endings, many are dos. I'd like to test each file to see if if is dos formatted, before I switch the line endings. How would I do this? Is there a flag I can test for? Something similar? ...

How to generate changelog: git log since last Hudson build?

I'm using Phing to do post build tasks in Hudson. I want to generate changelog containing all commits since last successful Hudson build. But looks like neither Hudson nor Git plugin for Hudson does not provide %last_build_time% variable. This would be satisfying solution, (but how to get the time?): git log --pretty="%s" --since="%la...

cd Terminal at a given directory after running a Python script?

I'm working on a simple Python script that can use subprocess and/or os to execute some commands, which is working fine. However, when the script exits I'd like to cd the actual Terminal (in this case OS X) so on exit, the new files are ready to use in the directory where the have been created. All the following (subprocess.Popen, os.sy...

How to intialize a variable from another script in bash?

How can I set my intial variables in a re-usable way? I tried to do this by invoking something like this in my child script: ./init.bash And inside init.bash: prod="false" if [ "$prod" == "prod" ] then RUN_DIR=/home/windsor/.scripts/websites JAVA_DIR=/home/windsor/prog/websitechecker OUT_DIR=/tmp/ DB="prod" else ...

bashscript for file search and replace!

Hey I try to write a littel bash script. This should copy a dir and all files in it. Then it should search each file and dir in this copied dir for a String (e.g @ForTestingOnly) and then this save the line number. Then it should go on and count each { and } as soon as the number is equals it should save againg the line number. => it sho...

How a script know his own name in bash?

I launch script.sh and inside it i want to know what is his name Is there a standard procedure to know the scripts name ? the idea is to be able to extract the name from teh full path + name contained in $0 Thanks ...

Bash completion for Maven escapes colon

I added bash completion for Maven following the docs: http://maven.apache.org/guides/mini/guide-bash-m2-completion.html Everything works well except for goals that use a colon. For instance, instead of mvn eclipse:eclipse completion escapes the colon mvn eclipse\:eclipse Any suggestions how this can be fixed? I'm using Ubuntu 8.1...

Using ed to manipulate files matched by find

Following the bash-hackers wiki's recommendation, I want to edit files using ed. In particular I want to do the following with ed instead of sed: find . -type f -exec sed -i -e 's/a/b/g' {} \; I see that ed doesn't have opt like sed's -e, so as far as I know, pipes and io redirections are the only way to work with it non-interactivel...

finding empty directories unix

i need to find empty directories for given list of directories some directories have directories inside it if inside directories also empty i can say main directory is empty otherwise it's not empty how can i test this for example A>A1(file1),A2 this is not empty beacuse of file1 B>B1(no file) this is empty C>C1,C2 this is empty ...

How can I output different shades of green to the terminal?

I'm currently using the following code to output text in green to the terminal: printf("%c[1;32mHello, world!\n", 27); However, I want more shades of green. What's the easiest way to accomplish this? ...

remsh rsh error redirect problem

I'm using the following command on HP-UX: remsh opera -l myuser crontab -l > /opt1/exp_opera_crontab 2>/opt/a.log and when I echo $? I get 0 because it's executing crontab -l on the remote machine. But I don't have opt1 directory so export won't be copied to my local machine in /opt1/exp_opera_crontab I don't get any error about thi...

Unescpaing huge single-line string on Linux

I ended up with a huge, single line string literal (don't ask me how) where everything is escaped (mostly), including new lines and double quotes. Problem is, I want the original string. The string is huge so I'm not even sure how to begin. Here's what I have: "This\n is \"nice\",\nain\'t it?" This is what I want: This is "nice", ai...

How does one find and copy files of the same extension, in different directories, to a single directory in linux?

So, How Do I find and copy all files, *.a that are in, ~/DIR{1,2,3,...} to ~/tmp/foo? ...

join 3 files by first Column with join (was awk) ?

i have three similar files, they are all like this: File A ID1 Value1a ID2 Value2a . . . IDN Value2n and i want an output like this Output ID1 Value1a Value1b Value1c ID2 Value2a Value2b Value2c ..... IDN ValueNa ValueNb ValueNc Looking to the first line, i want value1A to be the value of id1 in fileA, value1B the value of ...

Store value of os.system or os.popen

Hello, I want to grep the error's out of a log file and save the value as an error. When I use: errors = os.system("cat log.txt | grep 'ERROR' | wc -l") I get the return code that the command worked or not. When I use: errors = os.popen("cat log.txt | grep 'ERROR' | wc -l") I get what the command is trying to do. When I run this ...

Help with converting a Linux .bsh script to a vbs / wsh script (or other) for Windows

Hi, I have a Linux .bsh script, which I need to run on a Windows 7, and I’m having some difficulties with creating the script. I would like a script so I can run it in my cmd in windows or if the script could output to a file. The .bsh script looks as following: for ((r=0; r <$[0]; r++)) netcat localhost 4444 < $[1] $ done wait ...

Help with Cygwin bash file

Hi, I have a bash file, which I’m trying to run in Cygwin on a Windows 7 platform, but I gives me some odd errors when doing so. The bash file works on my Linux system. The bach file looks like this: for ((r=0; r <10; r++)) netcat localhost 4444 < myfile.file & done wait but I’m getting an error for my for-loop. More precise i...

Looking to reimplement build toolchain from bash/grep/sed/awk/(auto)make/configure to something more sane (e.g. boost.build, etc)

I currently maintain a few boxes that house a loosely related cornucopia of coding projects, databases and repositories (ranging from a homebrew *nix distro to my class notes), maintained by myself and a few equally pasty-skinned nerdy friends (all of said cornucopia is stored in SVN). The vast majority of our code is in C/C++/assembly ...

Stacking standard output of `su`

I've got some code that I wrote that uses a combination of bash and PHP command line scripting. The script is ran as root and then uses su to become various uses. I start a session like this: $result = `su SomeUser ./dothis.php` Here ./dothis.php is a script that may generate some output being stored in $result, but the problem is tha...

Is there a way to make linux CLI IO redirection persistent?

I have multiple piped commands, like this: find [options] | grep [options] | xargs grep [options] Each one of them can potentially produce errors (permissions errors, spaces-in-filenames errors, etc) that I am not interested in. So, I want to redirect all errors to /dev/null. I know I can do this with 2>/dev/null, for each command. Ca...