bash

How to iterate over assoziative array in bash

Based on an assoziative array in a bash script I need to iterate over it to get key & value. #!/bin/bash declare -A array array[foo]=bar array[bar]=foo I actually don't understand how to get the key while using a for-in loop. Thanks in advance! ...

How do you process the output of a command in bash line-by-line?

I need to process the shared library dependencies of a library from a bash script. The for command processes word-by-word: for DEPENDENCY in `otool -L MyApplication | sed 1d` do ... done What is the way to process the results line-by-line? ...

Is there a version of tac that gunzips the content? (like zcat)

I am working on a PHP script that needs to read log files in reverse line order. I currently do the following: <?php shell_exec("tac logfile.log > tmpfile.log"); $rFile = fopen("tmpfile.log", "r"); while (!feof($rFile)) { //logic } unlink("tmpfile.log"); ?> This works nicely as it switches the order of the lines in the file and ...

efficient way to merge a head file and part of a tail file and then to stdout

Actually I am in great agony recoverying a corrupt gzip file, possibly due to interrupted ftp transfer and then resume. After googling I found Recovering a damaged .gz file and am trying as it reads. What I'm doing now is merging a gzip header file with some last part of the damaged file varying the size of the last part. Then I test th...

How to fix up this problem with screen bash command?

I accidently deleted /var/run/screen/S-root/25771.pts-0 and when I try to run screen again screen bash ... it reports: /var/run/screen/S-root/25771.pts-0: No such file or directory How can I recover it? ...

Trying to make a filter with grep

I'm trying to make a filter that capture all the .exe file lines. For example, from this: [05/Apr/2010:11:00:01 -0300] /~mauro/Lista_conceitos_BD_2004.DOC 200 46080 [05/Apr/2010:11:00:54 -0300] /~lucia/articles/PROPOR96-Rino.pdf 200 153253 [05/Apr/2010:11:01:32 -0300] /~daniel_leite/RenomearTudo/setup.exe 200 1692017 [05/Apr/2010:11:...

Is it possible to make something like OSX Services for linux, by leveraging pipes ?

I was reading the concept of OSX Services and it seemed very cool to me to have utilities like Dictionary, highlight-text-and-open-in-browser and a million other services that provide functionality based on what the user is currently doing. I have heard it mention that this mechanism is more similar to how pipes work in *nix, rather tha...

How can a bash script write out a binary file, without using uudecode?

Hi all, I've got a little puzzler here for the bash scripting experts... I have a bash script that needs to create a small (80 byte) binary file when it runs. The contents of the file need to be contained inside the script itself (i.e. I don't want to just package the file along with the script). My script currently does it like this:...

Arithmetic problem with shell script

I've got some issues on scripting... if someone could help me, it would be really good ! My script has: VISITS=$((WR + RD)); SERVICE_DEMAND=$((VISITS*SERVICE_DEMAND)); And I'm getting this error: ./calc_serv_demand.sh: line 12: 0.0895406: syntax error: invalid arithmetic operator (error token is ".0895406") Can someone hel...

Clean way to launch the web browser from shell script ?

In a bash script, I need to launch the user web browser. There seems to be many ways of doing this: $BROWSER xdg-open gnome-open on GNOME www-browser x-www-browser ... Is there a more-standard-than-the-others way to do this that would work on most platforms, or should I just go with something like this: #/usr/bin/env bash if [ -n $...

Bash vi mode - bind "C-c" to escape from insert mode

Hi, I just discover the magic of using vi style in bash. Immediately, I'm trying to use C-c to escape from insert mode (into what's called movement mode) as I'm used to C-c to escape to command mode in vim. I searched around and found the command to rebind key in bash: "bind -m vi-insert C-c:vi-movement-mode" Then, I used "bind -P"...

Including Bash autocompletion with setuptools

I've got a couple packages in PyPI, and I'd like to include autocompletion features with both of them. How would you check that Bash autocompletion should be installed at all (check for /etc/bash_completion, maybe?), and how would you install it with setup.py (preferably using setuptools)? ...

Unix - File Creation Date

For an assignment I need to determine the creation time of a random file. As far as I know, Unix does not store the creation time (in contrast to *-BSD). I think I've read somewhere that you should ask for the modification time instead but I don't know where and asking Google doesn't give me a non-ambigious answser either. Any ideas? ...

How to make the hardware beep sound in Mac OS X 10.6

I just want that Mac OS X 10.6 does a hardware beep sound like in open suse and other distributions. I tried following approaches Terminal -> beep = -bash: beep: command not found Terminal -> say beep = voice speaks out beep (Not a Hardware beep but awesome ;) ) applescript -> beep = Macintosh bell (I want a Hardware beep!) Does anyb...

Bash script -e not detecting filename in a variable

In a BASH script, I'm trying to detect whether a file exists. The filename is in a variable but the -e command seems to be unable to detect the file. The following code always outputs "~/misc/tasks/drupal_backup.sh does not exist" filename="~/misc/tasks/drupal_backup.sh" if [ -e "$filename" ]; then echo "$filename exists" else ech...

Bash script - store stderr in variable

I'm writing a script to backup a database. I have the following line: mysqldump --user=$dbuser --password=$dbpswd \ --host=$host $mysqldb | gzip > $filename I want to assign the stderr to a variable, so that it will send an email to myself letting me know what happened if something goes wrong. I've found solutions to redirect stde...

How to add custom Java command-line options?

Hi! I'd like to add custom command-line options to my Java program. Here's an example: java -cp my.jar package.Main -i input.data -o output.data How can I achieve this. Currently I only get JVMJ9VM007E Command-line option unrecognised: -i Edit: The output of java -version java version "1.5.0" Java(TM) 2 Runtime Environment, Stand...

How to get all man pages installed on a system?

I would like to load some man pages onto my iPad in PDF format. I have very quickly put this together: #!/bin/bash output_directory="/Users/Shared/Local/Media/E-Books/Man_Pages/Mac_OS_X" man_pages_directory=/usr/share/man for man_pages_section in "${man_pages_directory}/man"?; do for man_page_path in "${man_pages_section}/"*; do ...

How do I remove newlines from a text file?

Hey there everyone ... I have the following data, and I need to put it all into one line... I have this: 22791 ; 14336 ; 22821 ; 34653 ; 21491 ; 25522 ; 33238 ; I need this: 22791;14336;22821;34653;21491;25522;33238; If anyone could help me it would be a great !! Thanks in advance! --------- EDIT No of these commands...

VNC Bash Problem

I'm having a curious problem with a little script to make a VNC connection to a remote host. The script just makes an SSH tunnel for the VNC session and then opens the viewer. It's only two lines, and when copied into the shell manually, it works fine. However, invoking the script causes the VNC viewer to fail with this error: main: ...