bash

Bash script directory detection and creation

I have a bash script that depends on a group of folders existing, but dont want to create the folders by hand every time I use the script on a new machine. Right now I have the following for directory detection and creation (taken from here): for i in {7..0} do if [ ! -d "backup.${i}" ]; then mkdir backup.${i} fi done This d...

Open window of an application and move it to a different Space in OSX, is it possible?

Hi, for some application I would like to have an "instance" of it running in Space (Apple's workspace) 4 and another one in number 2. How can I somehow tell (in bash/applescript or whatever) to an instance of an application, to "move" to Space number N? Applescript? Bash? External app? I want to do this automatic and for a lot of diffe...

Status bar in bash

Hello, Firstly, Thanks everyone for all your help. I can see the successful completion of my project in couple of days.. I need to know how to put a status bar in Shell Script, something like this. No_of_files=55 index=0 while [ $index -lt $No_of_files ] do echo -en "$index of $No_of_Files Completed" index=$((index + 1)) do...

Check for stdout or stderr

Hello folks, One of the binaries which I am using in my shell script is causing a segmentation fault (RETURN VALUE: 139) And even though, I am redirecting both stdout and stderr to a logfile, the Segmentation Fault error messages is displayed in the terminal when I am running the shell script. Is it possible to redirect this message ...

bash command to repeatedly emulate keypress on a proceess

The nmap tool has such a feature - when you're performing a scan [#nmap -A -T4 localhost] and press "Enter" - it displays kind of status information "Timing: About 6.17% done" Question - how can I force this keypress to happen repeatedly without touching a keyboard in bourne shell? ps: just trying to find a work-around for a bug in php...

Preserve colouring after piping grep to grep

There is a simlar question in Preserve ls colouring after grep’ing but it annoys me that if you pipe colored grep output into another grep that the coloring is not preserved. As an example grep --color WORD * | grep -v AVOID does not keep the color of the first output. But for me ls | grep FILE do keep the color, why the difference ? ...

Problems with Grep Command in bash script

Hi Guys, I'm having some rather unusual problems using grep in a bash script. Below is an example of the bash script code that I'm using that exhibits the behaviour: UNIQ_SCAN_INIT_POINT=1 cat "$FILE_BASENAME_LIST" | uniq -d >> $UNIQ_LIST sed '/^$/d' $UNIQ_LIST >> $UNIQ_LIST_FINAL UNIQ_LINE_COUNT=`wc -l $UNIQ_LIST_FINAL | cut -d \ -f...

While loop never ends

I'm working with bash and I'm trying to do something like this: A=1 while [ $A=1 ]; do read line echo $line | grep test >/dev/null A=$? echo $A done This script never ends even when the grep finishes successfully and A is set to 0. What am I missing here? Below is a sample of the output. $ ./test.sh asdf 1 te...

How do I write a pidfile in a windows batch file

Hi! I am writing some Java code that needs to be able to write a pidfile on Unix-like as well as windows machines. On the unix machines I write out a bash shell script that contains something like this command 1>/dev/null 2>&1 & echo $! > pidfile It executes a command, redirects all output into nirwana and puts command into the backg...

Is there a simple way in linux to strip a website of text from command line?

I've been searching for a command line tool that would turn html code into just the text that would appear on the site... so it would be equivalent to in a web browser selecting everything and then pasting it into a text editor... Anyone know of something in Ubuntu that would do this? I'm trying to write a script to parse some webpages...

How do you escape a user-provided search term that you don't want evaluated for sed?

I'm trying to escape a user-provided search string that can contain any arbitrary character and give it to sed, but can't figure out how to make it safe for sed to use. In sed, we do s/search/replace/, and I want to search for exactly the characters in the search string without sed interpreting them (e.g., the '/' in 'my/path' would not ...

Bash Scripting and bc

I'm trying to write a bash script and I needed to do some floating point math. Basically I want to do something like this: NUM=$(echo "scale=25;$1/10" | bc) if [ $? -ne 0 ] then echo bad fi The problem I'm running into is $? tends to hold the output from the echo program and not the bc call. Is there a way I save the output from the...

Pipe Java to Grep: Why not working?

I am trying to run this dreadfully simple command in Bash java -cp nasa-top-secret.jar gov.nasa.RocketToMoon | grep -v codehaus but grep is not working (it does not filter out my string). How can I filter my java output using grep? ...

Can a shell script indicate that its lines be loaded into memory initially?

This is a little thing that bothers me every now and then: I write a shell script (bash) for a quick and dirty job I run the script, and it runs for quite a while While it's running, I edit a few lines in the script, configuring it for a different job But the first process is still reading the same script file and gets all screwed up. ...

What is a reliable way to determine which shared library will be loaded across linux platforms?

Hello, I need to find out which library will be loaded given in the information returned from /sbin/ldconfig. I came up with the following: #!/bin/bash echo $(dirname $(/sbin/ldconfig -p | awk "/$1/ {print \$4}" | head -n 1)) Running this results with: $ whichlib libGL.so /usr/X11R6/lib This a two part question: Will this produ...

What is the most compact or efficient way of doing several subsitutions in a file in bash

Hi, I have a file data.base which looks like: 1234 XXXX 4321 XXXX 9884 ZZZZ 5454 YYYY 4311 YYYY 9882 ZZZZ 9976 ZZZZ ( ... random occurrences like this till 10000 lines) I would like to create a file called data.case which derives from data.base just with substitutions of XXXX, YYYY, ZZZZ for float numbers. I wonder what would be th...

Can I read line from a heredoc in bash?

Here's what I'm trying. What I want is the last echo to say "one two three four test1..." as it loops. It's not working; read line is coming up empty. Is there something subtle here or is this just not going to work? array=( one two three ) echo ${array[@]} #one two three array=( ${array[@]} four ) echo ${array[@]} #one two three four ...

Is there a way to make a link clickable in the OSX Terminal?

I am planning on developing an Mxmlc to Textmate formatter, one that formats mxmlc errors as clickable links, so you can open them up quickly in Textmate as Textmate has a url scheme e.g.: txmt://open/?url=file://~/.bash_profile&line=11&column=2. I am wondering if it is possible to display links in your OSX terminal, that are also clic...

Add spaces to the end of some Bash autocomplete options, but not to others?

I'm trying to create a Bash completion script for a Java program. A typical invocation of that program might look like this: $ javaProgram -Dproperty=foo option1 option2 Part of my script will be to suggest the various Java properties that are available for this program (i.e., when the user types "-D", the script would suggest, say, ...

What does the ampersand indicate in this bash command 1>&2

Hi Quick one, 2>&1 redirect stderr to stdout, but what does the ampersand mean. I know if we had 2 > 1 it would output to file named 1, what does the ampersand do ? Thanks ...