bash

What goodies are present in UNIX shells sans BASH?

I have been using 'bash' since the time I have been using Unix- Linux/Solaris. Now, I am interested to know what do shells like 'ksh','zsh' offer better? What do 'geeks' use? ...

How does "while (sleep 100 &!) do; done" work in zsh, and how could it be replicated in bash?

According to wikipedia ( http://en.wikipedia.org/wiki/Fork_bomb ), the forkbomb ":(){ :|:& };:" can be stopped with the zsh command "while (sleep 100 &!) do; done", which will supposedly spawn sleep 100 processes until all the forkbomb processes are gone. This seems like magic to me. Can anybody explain why/how this works? I'm especia...

Bash scripting errors and funnies

The command-line can be powerful but it can also be risky, which is why it is never recommended to login as root for your day-to-day work. Sometimes the command line can catch you out if you're not careful. So for example rm -rf . /dir instead of rm -rf ./dir can have a completely different result to what you intended. Here is a great c...

Change from HTML character refrences to utf-8 in a bash script ie. ā becomes ā

How would you go about translating a document that contains the following character references to their actual readable characters in a bash script? ā á ǎ à ē é ě è ī í ǐ ì ǖ ǘ ǚ ǜ ü ǖ ǘ ǚ ǜ ü These change in order to ā á ǎ à ...

alternate way to trigger reverse-i-search without pressing ctrl+r in bash

The reverse-i-search facility in bash is useful, but it is unlike most other bash commands in that it seems to be bound to a keybinding (Ctrl-R). How can a user trigger this facility using an alias or typed-in command instead? ...

How do you run a command in iTerm when it launches?

I'm working on configuring the iTerm terminal emulator for the Mac to do what I want. Apparently everything is done through what they call "bookmarks." OK, fine. I'm trying to create a bookmark that will open a tab, cd to a certain Rails project, and run the command script/server. What's supposed to happen is that this will launch the se...

Stop bash script if unchecked Java Exception is thrown

I am running a java program from within a Bash script. If the java program throws an unchecked exception, I want to stop the bash script rather than the script continuing execution of the next command. How to do this? My script looks something like the following: #!/bin/bash javac *.java java -ea HelloWorld > HelloWorld.txt mv Hell...

Linux terminal output redirection

I want to redirect the output of a bash script to a file. The script is: #!/bin/bash echo "recursive c" for ((i=0;i<=20;i+=1)); do time ./recursive done But if I run it like this: script.sh >> temp.txt only the output of ./recursive will be captured in the file. I want to capture the output of time command in the file. ...

Finding files ISO-8859-1 encoded?

I have a bunch of files with a mixtures of encodings mainly ISO-8859-1 and UTF-8. I would like to make all files UTF-8, but when trying to batch encode this files using iconv some problems arise. (Files cuts by half, etc.) I supposse the reason is that iconv requires to know the 'from' encoding, so if the command looks like this iconv...

BASH Script to cd to directory with spaces in pathname

Argggg. I've been struggling with this stupid problem for days and I can't find an answer. I'm using BASH on Mac OS X and I'd like to create a simple executable script file that would change to another directory when it's run. However, the path to that directory has spaces in it. How the heck do you do this? This is what I have... ...

How can I use bash syntax in Makefile targets?

I often find bash syntax very helpful, e.g. process substitution like in diff <(sort file1) <(sort file2). Is it possible to use such bash commands in a Makefile? I'm thinking of something like this: file-differences: diff <(sort file1) <(sort file2) > $@ In my GNU Make 3.80 this will give an error since it uses the shell instead...

Upstart calling script (for inserted USB-drive)

Hi, I know that Ubuntu (and Fedora) uses Upstart istead of the classical System V init daemon (SysVinit). I would like to know how to detect when a USB-drive has been inserted, mount it and copy some files to it. I would like Upstart to call my own script for this. If it is possible I would like Upstart to call the script for a specifi...

Bash scripting and user home from root account (Linux)

I'm writing an install script in bash for an application on Linux. This script copies some files into /usr/bin and /usr/share, so it needs to be executed by a root user, furthermore it makes an hidden directory in the $HOME dir for configuration files. Here is the problem: if a normal user wants to install the program, he needs to be r...

A process command in top

The problem comes up when you run couple of python scripts. in top at command, it shows only 'python' with these scripts. How to rename a process or otherwise tag it so that I could tell them apart in top? ...

Another shell open when at server?

How can I have another Terminal open when I am at my server by ssh? I do not want to type my password twice to get another terminal for my server. Perhaps, Bash has buffers similarly as Vim. ...

Check if a program exists from a bash script.

How would I validate that a program exists? Which would then either return an error and exit or continue with the script. It seems like it should be easy, but it's been stumping me. ...

Is there a good, online tutorial for learning intermediate-to-advanced Bash programmable completion?

My current skill level with programmable completion is pretty basic — about at "complete -d cd". I'd like to significantly increase my knowledge (and use) of completion to increase my CLI productivity, but I'm having trouble finding an online resource which has much substance. The vast majority of what I'm able to dig up via Google boi...

Redirect STDERR / STDOUT of a process AFTER it's been started, using command line?

In the shell you can do redirection, > <, etc., but how about AFTER a program is started? Here's how I came to ask this question: a program running in the background of my terminal keeps outputting annoying text. It's an important process so I have to open another shell to avoid the text. I'd like to be able to >/dev/null or some other...

How do you execute a command on a remote system insde a BASH script?

As part of an intricate BASH script, I'd like to execute a command on a remote system from within the script itself. Right now, I run the script which tailors files for the remote system and uploads them, then through a ssh login I execute a single command. So for full marks: How do I log into the remote system from the bash script (...

How can I print intermediate results from a pipeline to the screen?

Duplicate http://stackoverflow.com/questions/570984/how-can-i-gzip-standard-in-to-a-file-and-also-print-standard-in-to-standard-out I'm trying to count the lines from a command and I'd also like to see the lines as they go by. My initial thought was to use the tee command: complicated_command | tee - | wc -l But that simply doubles ...