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
3answers
531 views

How do I quickly move the cursor to the end in bash in vi mode?

When I'm in insert mode and I move left from the last cursor position (the empty spot to the right of the last character), then I can't go back to that position anymore. I have to type Esc$a (or ...
4
votes
2answers
879 views

Wait for a X window to appear/disappear (in a sane way)

Inside a shell script, I need to wait for a window that has a string on its title to appear, do some action, and then wait for it to disappear, and do some other action. Until yesterday, I had this ...
14
votes
6answers
2k views

Is it common to split larger script into multiple scripts and source them in the main script?

At the moment I'm developing a larger Bash script (it's an Open Source project of mine) and it's starting to become a mess. I've split up logic into functions, use local variables where I can and have ...
1
vote
1answer
530 views

how to locally redefine 'command_not_found_handle'?

I'd like to make a particular bash script failfast when it cannot find a command, while retaining globally the usual friendly command_not_found behavior. E.g., if I save the following to /tmp/foo.sh, ...
2
votes
1answer
86 views

process continous output of synclient

I am using synclient to track the position of finger on the touchpad. I use the following command. synclient -m 100 | awk '{print $2,$3}' This command gives the 'x' and 'y' co-ordinate on the ...
-1
votes
4answers
558 views

Ending Process Infinite Loop Input Redirection

Edit: I realized that the program I was trying to run had an infinite loop after scanning all my input. Then just prints out infinitely so it'll never read the EOF. It'll read the last input then go ...
3
votes
3answers
487 views

Including sub-parameters in help options to execute wisely without getopt or getopts?

I am writing a script which can choose a file and print specific content. For example, san#./script.sh Expected Usage : ./script.sh --file1 --dns (Here it checks for file1, search for dns name and ...
3
votes
2answers
638 views

How to open process substituted file from php?

Here's what I tried to do myself: $ type 1.sh #!/bin/bash -eu php -r 'var_dump(file_get_contents($_SERVER["argv"][1]));' -- <(echo 1) $ ./1.sh PHP Warning: file_get_contents(/dev/fd/63): failed ...
0
votes
2answers
2k views

Rename multiple files in UNix directory [duplicate]

I have files in unix directory in below format using sed or some other commands. Owner.Env.File_010513_1200_ver1.expdp Owner.Env.File_010513_1200_ver2.expdp Owner.Env.File_010513_1200_ver3.expdp ...
6
votes
2answers
3k views

Setuid bit seems to have no effect on bash

I was experimenting a bit and noticed something strange: setting the setuid bit on a copy of bash located at /usr/bin/bash-test seemed to have no effect. When I ran an instance of bash-test, my home ...
13
votes
2answers
33k views

Can I redirect output to a log file and background a process at the same time?

Can I redirect output to a log file and background a process at the same time? In other words, can I do something like this? nohup java -jar myProgram.jar 2>$1 > output.log & Or, is that ...
4
votes
5answers
210 views

Getting two fields from same line together

I've got a situation where I've got several lines, and I need two different fields out of each of them. To be specific, I have a list of references in a bibliography and I want to get the last name ...
1
vote
1answer
656 views

what's wrong with embedding php scripts inside bash ones?

I was trying to use php inside bash script, but I came across several problems. My first try failed with error about bash not being able to find end of here-document. The minimal version that still ...
8
votes
4answers
4k views

Hybrid code in shell scripts. Sharing variables

This answer discusses how to run a multi-line Python snippet from the command line in a terminal. I noticed that the answer works great within shell scripts, even with nested indentation, which is ...
5
votes
2answers
894 views

Wrap command in the prompt

Is it possible to insert a separator after the command in a prompt? This is an example: ~/Desktop: ls -al ------------------------------------- total 80 drwx------+ 6 eddie staff 204B Apr 29 ...
1
vote
2answers
5k views

How to unset range of array in Bash

I'm trying to delete range of array element but it's fail.. My array root@ubuntu:~/work# echo ${a[@]} cocacola.com airtel.com pepsi.com Print 0-1 array looks ok root@ubuntu:~/work# echo ...
0
votes
1answer
56 views

Watch goes blank on refresh [duplicate]

I'm running the following command in watch. Works for the first one but subsequent ones go blank watch diff <(pacman -Q) <(ssh kate "pacman -Q")
2
votes
1answer
468 views

bash script - supervisor program

I have to write a shell-script that have to do the following tasks: -in every 5 seconds it saves:     -how many users are using joe and/or vi;     -if ...
6
votes
1answer
641 views

Custom key bindings for vi shell mode, ie, “set -o vi”?

I just discovered the wonders of set -o vi, and am curious if it is possible to customize this vi shell mode in some of the same ways you can customized vi or vim? For example, create a custom key ...
0
votes
2answers
6k views

bash - reading user variable into bash script grep

I've tried every possible combination to get this bash script working. It's part of a larger script, and it basically prompts for a username (to check if it exists) and returns the appropriate ...
6
votes
2answers
559 views

Bash : command line with optional arguments

I'm running this kind of code: #!/usr/bin/env bash set -u exclude1='--exclude=/path/*' exclude2='--exclude=/path with spaces/*' exclude3='' # any 'exclude' can be empty tar -czf backup.tgz ...
3
votes
3answers
1k views

Colorize Bash Console Color

I need to be able to set my CentOS 6.4 bash prompt color to yellow. I've managed to find where to set this (.bashrc) and the ANSI color for yellow (\e[0;33m). I've setup my prompt as follows: ...
17
votes
5answers
1k views

In what situations would a user not let the shell record his command into history?

If I add export HISTCONTROL=ignorespace in .bashrc, bash won't record any commands which have whitespace before them into history. But I do not understand under what situations it will be useful. ...
2
votes
2answers
221 views

Script for opening emacs in two different ways

I've attempted to write a small script that will by default open emacs with emacs -nw foo by simply typing emacs foo and when I want a window typing emacs foo & The script I attempted to ...
0
votes
1answer
96 views

can someone fix my PS1 for bash

I seem to have too many colour escapes so it only works in some prompts - can someone please correct for me ? PS1='\[\e[0:35m[\u@\e[0:33m\h\e[m \e[0:35m\w]\e[m \e[0:33m`git branch 2> /dev/null | ...
2
votes
3answers
894 views

Very strange behavior with grep and IFS

I'm having trouble using grep, the returned results are "n-empty", I mean without the 'n' character... This is the script sample : OLDIFS=$IFS IFS="\\n" i=$(grep -ril $1 *) echo $i IFS=$OLDIFS ...
26
votes
4answers
4k views

difference between “function foo() {}” and “foo() {}”

I can define bash functions using or omitting the function keyword. Is there any difference? #!/bin/bash function foo() { echo "foo" } bar() { echo "bar" } foo bar Both calls to functions ...
10
votes
2answers
435 views

Expand subshell before executing it?

I often run commands using subshells, and sometimes would like to have the subshells expanded before I run something.. This way I could verify what I'm doing, and possibly edit what's about to happen ...
10
votes
3answers
5k views

How to turn off the beep only in bash tab-complete

I find the beep useful for some things, so I only want to turn it off for tab completion (I'm not asking how to completely turn it off, that has already been answered in a different question on ...
1
vote
3answers
201 views

string and number comparsion in bash in test statements?

I am not sure about this comparison i am doing: if [ "$exit_status" -eq 0 ];then #some statements fi is this correct way of comparing numbers or quotes make the variable exit_status a ...
2
votes
1answer
151 views

replacement inside parallel command string

I want to download multiple files and save them to the md5 sum of its name: cat list | parallel -j4 "md5=$(wget -O - {} | tee tmpfile_{#} | md5sum | cut -d ' ' -f 1); mv tmpfile_{#} $md5" but the ...
1
vote
1answer
2k views

Multiple option arguments using getopts in bash

I am trying to process command line arguments using getopts in bash. One of the requirements is for the processing of an arbitrary number of option arguments (without the use of quotes). 1st example ...
44
votes
3answers
23k views

How to cycle through reverse-i-search in BASH?

In the terminal, I can type CRTL+R to search for a matching command previously typed in BASH. E.g., if I type CTRL+R then grep is lists my last grep command, and I can hit enter to use it. This only ...
2
votes
2answers
125 views

List all my variables [duplicate]

I'm just learning the basics, including how to declare and mess around with variables. Is there a simple way to display a list of all the variables I've named? (Everything I've found by searching only ...
4
votes
3answers
226 views

CD into directory from HISTORY in a bash script or alias e.g. $(!!)

I often want to change into the directory of a file on my file system, but I'm not sure where the file is. I search for it like so: find -type f -name "myfile.txt" Lets say for the sake of ...
6
votes
2answers
320 views

What does which's --tty-only option do?

I just realized that my sysadmin has created a global alias for which: alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde' The which manpage just says: Stop ...
2
votes
4answers
812 views

Problem understanding 'hash' command in a .sh file

So I wanted to install etherpad lite on a linux machine. If I try to run it, I will get the Error "Please install node.js ( http://nodejs.org )" the command 'which node' gives me the correct path to ...
4
votes
3answers
334 views

What process is running before I even get a prompt?

When I log in to a specific server I see the following: Note that I get get Last login: ... information but no prompt. I hit Ctrl+C and only then do I get my prompt, thus proving that my username ...
3
votes
0answers
724 views

.bashrc alias not working [closed]

I have set up a few aliases in my .bashrc file, like the following: alias ras='rails server' alias res='redis-server' alias rc='rails console' alias be='bundle exec' # git alias's are as follows ...
5
votes
2answers
293 views

Combining multiple process substitution

Suppose you tried something like this: $ paste ../data/file-{A,B,C}.dat and realize that you want to sort each file (numerically, let's suppose) before pasting. Then, using process substitution, ...
3
votes
1answer
112 views

how to record command which execute a programme suid

My question: Is there a way to record all commands who execute a suid programme? Like what .bash_history do, but only the setuid programmes.
2
votes
3answers
248 views

In bash, how can I erase an alias without logout? [duplicate]

I had an alias in my .bashrc and I really don't want it anymore. I erased the alias, but my bash already has this alias loaded. Can I erase this alias from this bash without logging out?
3
votes
2answers
344 views

Automated partition selection in bash script

I'm trying to write a bash script to run from Linux on a CD or flashdrive that can mount Windows and change stuff, but I don't know how to go about detecting which partition/drive is Windows. My best ...
1
vote
0answers
589 views

Create adhoc network when disconnected from network

I am using ArchLinux and want to create an AdHoc network automatically when the connection to the home network drops (or the home network can't be connected to on startup). How can I achieve this? I ...
2
votes
2answers
277 views

Why won't the for loop execute on directory

In the following script, the first for loop executes as expected, but not the second. I do not get any error, it seems that the script just hangs. HOME=/root/mydir DIR=$HOME/var DIRWORK=$HOME/Local ...
2
votes
0answers
83 views

LXC apparmor profile limits executing scripts in /run/*

LXC is blocking a trusted container from running scripts in /run/*, how do I configure LXC to allow scripts to run here?
0
votes
1answer
141 views

Input/output file.txt in bash shell [duplicate]

I don't know how to read input array number in input.txt and write result in output.txt. Example: input.txt have array 7 8 9 2 write result sort in output.txt 2 7 8 9 How can I do it?
3
votes
2answers
87 views

Specify script to run with SSH upon login

I would like to know if there is a way to specify what script to run (on the remote machine) at login. I'm logging into a Debian box with key-pair authentiation (no password needed). The script ...
5
votes
1answer
875 views

A script's background process is still alive after closing the terminal

This is more of a process management/signal handling question than a Bash question. It just uses Bash to explain the issue. I'm running a Bash script in which I run a background process. This is the ...
3
votes
2answers
2k views

Calling bash from sh (dash) with commands read from args, and “Unterminated quoted string”/“unexpected EOF”

Just thought I'd document this: I'm trying something very simple - set env variable in bash, and print it out: $ bash -c "a=1; echo a$a;" a $ bash -c "a=1; echo a\$a;" a1 Now I'd want this same ...