Questions about bash only, as opposed to other Bourne/POSIX shells. For all Bourne/POSIX-style shells, use the /shell tag instead.

learn more… | top users | synonyms

5
votes
2answers
1k views

Why doesn't “rm *” work when there are files that begin with a hyphen?

from: http://seclists.org/fulldisclosure/2011/Sep/190 [USER@MACHINE ~] mkdir ejha [USER@MACHINE ~] cd ejha/ [USER@MACHINE ~/ejha] touch ize [USER@MACHINE ~/ejha] touch -- -f -i [USER@MACHINE ...
5
votes
3answers
923 views

How can I reset all the bind keys in my Bash?

I bound some keys by mistake, and they don't work any more, such as HOME, END, UP, DOWN, LEFT, RIGHT. Is there a way to reset all the bound keys to their original state?
5
votes
3answers
1k views

How should I add users non-interactively?

I have a set of users I need to add to a new system as part of a BASH script that preps my server. How can I non-interactively add the user, create their home directory, set the group, and enter a ...
3
votes
5answers
903 views

How can I test whether connection to the given host/port is established in Bash?

Currently I'm using netstat for this: if netstat -an | grep ESTABLISHED | grep $address:$port > /dev/null; then # command fi Is there a more elegant solution?
7
votes
2answers
979 views

sharing or synchronizing history between Zsh and Bash

I often find myself switching between Bash and Zsh, and using the history search functionality to recover a command. However, since Bash and Zsh have different history files, I often find that the ...
3
votes
1answer
2k views

Showing GNU screen session name and window title in shell prompt

Is there a way to present the GNU Screen session name and window title in the prompt of the shell (let us say, the Bash prompt defined by PS1)?
2
votes
2answers
472 views

Script to prepend the files path to a file recursively

I work as a grader and files submitted to me end up in a folder named with the student's name which is itself inside a specific folder on my linux share. Currently I go through each source file and ...
10
votes
5answers
15k views

Is there a way to set the size of the history list in bash to more than 5000 lines?

No matter how much I set the HISTSIZE environment variable to be larger than 5000, when printing the history list with the history builtin, it prints only the last 5000 commands. I need that because I ...
6
votes
1answer
1k views

Customizing bash shell: Bold/color the command

There are a number of tutorials/posts online (e.g. http://www.cyberciti.biz/faq/bash-shell-change-the-color-of-my-shell-prompt-under-linux-or-unix/) about how to customize your prompt in bash by ...
2
votes
1answer
149 views

Need to find a cronjob

I have a problem, some user ,and I'm not sure who, on one of my servers wrote a cronjob that executes every night at midnight. The cronjob creates a sql dump of a database which is then grabbed by ...
71
votes
13answers
98k views

How can I resolve a hostname to an IP address in a Bash script?

What's the most concise way to resolve a hostname to an IP address in a Bash script? I'm using Arch Linux.
4
votes
4answers
1k views

Which stream does Bash write its prompt to?

I am trying to redirect all output from bash (prompt, user input, results) to a file Example: /bin/bash > file.txt 2>&1 I thought that would work, but I'm not getting the prompt. Can ...
4
votes
1answer
681 views

How to stop Bash appending history

I am having a lot of trouble setting up the terminal history of Bash the way I want. I would like to have no duplicate entries and if I enter a command I want it saved and the duplicates above ...
2
votes
1answer
1k views

Load my .profile for bash in Emacs terminal buffer? (multi-term mode)

I've got multi-term mode (derived from ansi-term) with bash started in Emacs 23.3, which is a terminal emulator running in Emacs. However, I noticed that it did not load my user profile, including ...
3
votes
2answers
327 views

Using `select` command to print menu in Linux

I am trying to implement a simple menu using select command. The script (for testing purposes) is as follows #!/bin/bash echo "*******************" PS3='Select an option and press Enter: ' ...
7
votes
1answer
461 views

Note-taking and outlining using Vi: On startup, highlight tags and display tags in a preview window [duplicate]

I am using vi as a note-taking and outlining tool and therefore I thought that this stackexchange site would be appropriate to ask this question. I am constructing the "tags" file by myself. What I ...
0
votes
2answers
186 views

How to put Mysql path in bash profile on MacBook Pro 10.6.8

I want to put a mysql path into the bash profile of my macbook pro. How do I access the bash file and then make it visible in the finder so I can open it with a text editor and put in the path?
1
vote
2answers
607 views

Unix read -p command causes bash error, how do I fix it?

I'm trying to prompt the user for a comment function comment { if [ ! $1 ] then read -p "enter checkin comment < " COMMENT; else export COMMENT="$1" fi if [ ! $COMMENT ] ...
3
votes
3answers
5k views

Is there a way to write a script to do ftp login so I don't have to type things over and over again?

I am recently working extensively with a remote system via ftp connection, since the session time is so short that I have to re-login quite often when I finish my work on my local machine, so I need a ...
4
votes
2answers
713 views

TinyCore Linux & RVM

I'm running TinyCore Linux and when I tried to install RVM (needed a portable linux distro for QA Automation) I keep getting an error sh: syntax error:unexpected redirection. I am unsure why I am ...
7
votes
4answers
4k views

Make cd automatically ls

I find that I often do the following: %> cd bla/bla %> ls I would like it that whenever I cd into a directory it automatically does an ls. I fiddled with my .bashrc for a while, but couldn't ...
3
votes
1answer
326 views

Removing redirection operator does not change output. Why?

I saw this usage of redirection somewhere, and thought it was a typo: grep root < /etc/passwd But after I run it, I saw that it gives the same output with grep root /etc/passwd: $ grep root ...
4
votes
1answer
89 views

Quoting in a function results in error

How should I write the command variable to get the expected behavior? #!/bin/bash function f ( ) { echo "$2" } command="f --option=\"One Two Three\" --another_option=\"Four Five Six\"" $command ...
7
votes
2answers
798 views

How to hinder root from running a script

The Glassfish application server provides scripts to administer the application server and also start and stop them and I would like to restrict the root user from running this script. The reason is ...
4
votes
1answer
2k views

shorthand for feeding contents of multiple files to the stdin of a script

Hi good people of this community, Say I have a script called script, that reads from stdin and spits out some results to the screen. If I wanted to feed it contents of one file, I would have typed: ...
3
votes
3answers
2k views

How can I test if a program is running from within a script

Let's assume that another user started a bunzip process, and I have a script that I'd like to start running after that bunzip finishes. What's the best way to check from inside my script that the ...
4
votes
3answers
1k views

Indirect return of all elements in an array

The Bash man page describes use of ${!a} to return the contents of the variable whose name is the contents of a (a level of indirection). I'd like to know how to return all elements in an array using ...
8
votes
2answers
1k views

Why does a bash here-string add a trailing newline char?

The following examples show that a newline is added to a here-string. Why is this done? xxd -p <<<'a' # output: 610a xxd -p <<<'a ' # output: 610a0a
8
votes
6answers
465 views

How to disable emacs here document completion

When editing a bash script file with emacs, and trying to enter <<<, at the second < emacs insert a template for a here document, like in the following example: <<EOF EOF This is ...
22
votes
7answers
17k views

How to add newlines into variables in bash script

When I do str="Hello World\n===========\n" I get the \n printed out too. How can I have newlines then?
3
votes
2answers
379 views

Why does $((40-35)) turn into 5?

What kind of strange shell syntax is hidden behind $((40-35)) and how come it calculates a value? Example: $> echo $((40-35)) 5
3
votes
1answer
3k views

Compress a directory using tar/gz over SSH to local computer?

I'd like to essentially tar/gz a directory on a remote machine and save the file to my local computer without having to connect back into my local machine from the remote one. Is there a way to do ...
5
votes
2answers
811 views

What do these commands (`tar`) actually do? Is there a better way?

I am going over some documentation pertaining to creating a distro repo. However, I cannot understand exactly what these commands perform: # cd /mnt/ # ls centos-1 centos-2 centos-3 # for i in 1 2 ...
4
votes
2answers
156 views

Why do newlines mess up my while condition?

I have a while loop that allows setting variables when written one way but does not allow it when written another way. Why is that? This prints var as 1234 and does not print var2 #!/bin/bash ...
2
votes
2answers
2k views

Displaying and updating a counter in bash

I think it's something like this: (Fedora14/bash) #!/bin/bash for i in {0..10..1}; do echo -e "$i"'\c' echo -e "\n\r" sleep 1 done But it doesn't work. Purpose: like this, but without the ...
-1
votes
1answer
1k views

Loop examples in bash [closed]

Any examples for "loop" in bash? for i in {1..5}; do echo $i; done 1 2 3 4 5 AND for i in 1 2 3 4 5; do echo "Welcome $i times"; done Welcome 1 times Welcome 2 times Welcome 3 times Welcome 4 ...
3
votes
4answers
1k views

How to run java process to be seen not as 'java…' in processes list?

Is it possible to run a Java process in Linux in a way that it could be seen in ps as some sort of alias? It would be easier to restart it when it is down.
4
votes
4answers
997 views

How can I remove a specific string from a file only if there are other lines in the file?

How can I remove a specific string from a file ONLY if there are other lines in the file? For example, don't touch this file: cat file.txt ASDF but remove "ASDF" from this file: cat file.txt ASDF ...
6
votes
1answer
1k views

All about ssh ProxyCommand

I am looking for an in-depth explanation of the following ProxyCommand, down to the nuts and bolts of its operation, please. Can you kindly completely dissect it for me and improve on it if you can? ...
3
votes
3answers
2k views

executing multiple greps in a single find command

I want to use find command to find some files containing multiple patterns at the same time. I tried something like this: find . -name "*.xml" -exec grep -iH keyword1 + && grep -iH ...
6
votes
5answers
576 views

copy consumed output to stdout when stdout is redirected to a file

Given a command the output of which is being processed by, for example, grep I also want the actual output to be included in the log file for debugging purposes. For example if I have the following ...
3
votes
2answers
622 views

How to use $? and test to check function?

#!/bin/sh function checkExit(){ if test "$?" != "0"; then echo Command $1 exited with abnormal status exit 1; else echo $? fi } function echoThenRun () { # echo and then ...
1
vote
3answers
2k views

Testing if a process is running via if and -z

I'm have a process on my system which is notorious for crashing, and is kind of mission critical, my network manager. In any case, I need to write a loop which tests if it's running and starts it if ...
2
votes
3answers
152 views

How to pass lines from a file to a bash script, so that each line remains undivided, even if there are spaces?

Given: $ cat lines.txt a/b 'c/d e/f' $ cat 1.sh #!/bin/sh ./2.sh `cat lines.txt` $ cat 2.sh #!/bin/sh echo p1=$1 echo p2=$2 echo p3=$3 $ ./1.sh p1=a/b p2='c/d p3=e/f' How do I change lines.txt ...
4
votes
2answers
973 views

What is the “caller” command?

I'm running Ubuntu 10.10 with openbox running on top. I noticed today a command called caller, however there is no man page, it does not respond to any input (or --help) and whereis doesn't find it. ...
2
votes
3answers
499 views

variable concatenation not working?

I have a simple bash shell script which is driving me bonkers. All I want to do is run a command which returns a result which I will then use in another command. The result of the first command ...
6
votes
2answers
698 views

Using bash “double paren” arithmetic expansion, math fails with leading zero

I have a simple script that deals with hours and minutes. If I want to calculate number of minutes since midnight having a string s hh:mm I tried splitting string then doing hh * 60 + mm My problem ...
3
votes
2answers
187 views

filename with no spaces from two command lines

I am running two Linux commands and I want to put the resulting values together in a filename with no spaces and a dot separating the two values. So far, I've got this: pid=`sudo dmidecode -s ...
4
votes
2answers
5k views

Why does the exclamation mark `!` sometimes upset bash?

I realize that ! has special significance on the commandline in the context of the commandline history, but aside from that, in a runing script the exclamation mark can sometimes cause a parsing ...
2
votes
2answers
2k views

Bash color output fails

Is it sed or echo problem? What I'm doing wrong? $> cat ~/bin/color_test.sh #!/bin/bash ColorOff='\e[0m' # Text Reset BWhite='\e[1;37m' # Bold White string="test TEST test" echo -e ...