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

11
votes
1answer
3k views

Terminal autocomplete: cycle through suggestions

I had this on my Ubuntu setup and since I switched to Fedora I want to set it and I forgot how... The idea is simple : I don't want the terminal to show me suggestions when I double tab, instead I ...
2
votes
2answers
379 views

add “check if fetchmail is running” to this script

while ! postqueue -p | grep -q empty; do sleep 1 done killall wvdial this script checks if my mail queue is empty, then disconnects my modem. now i would like to add also a checking to fetchmail ...
9
votes
4answers
570 views

Bash vi mode configuration to default to command mode

Is it possible to configure bash vi mode so that initially it is in command mode instead on insert mode? I find that I have to press Esc far too much. It seems that there is possibility to specify ...
7
votes
3answers
2k views

Piping STDERR vs. STDOUT

According to "Linux: The Complete Reference 6th Edition" (pg. 44), you can pipe only STDERR using the |& redirection symbols. I've written a pretty simple script to test this: #!/bin/bash echo ...
6
votes
2answers
5k views

How can I trap a program that returns 139 (segmentation fault) in bash?

I have a bash script that tests some programs and one of the program returns Segmentation fault so I tried to add a trap in the head of my script: trap "echo 'segfault occured!'" SIGSEGV That ...
4
votes
3answers
4k views

How I can know the IP address of other users logged at the same remote machine?

I can see the names of other users on the remote machine with the who command... I'd also like know the IP address of those users... I was trying with the commands /sbin/ifconfing and netstat but I ...
24
votes
3answers
11k views

Reading lines from a file with bash: for vs. while

I'm trying to read a text file and do something with each line, using a bash script. So, I have a list that looks like this: server1 server2 server3 server4 I thought I could loop over this using ...
2
votes
2answers
770 views

Adding 2 lines in text file stanza

I have a text file divided in stanzas. Each stanza starts with a [keyword] and ends with a blank line. Something like this: [keyword1] param1 = value1 param2 = value2 param3 = value3 [keyword2] ...
7
votes
7answers
2k views

Bash - Continuous String Manipulation

#!/bin/bash FILE="$(basename "$1")" FILE="${FILE/%.jpeg/.jpg}" Is there anyway to glue these two lines together into a one-liner?
28
votes
1answer
857 views

Avoiding “BASH-isms” in shell scripts

Does there exist a tool similar to Perl::Critic that will inspect your shell scripts and point out flaws, portability issues, uses of non-standard programs without fallbacks, depreciated program uses, ...
2
votes
0answers
98 views

“cd //” and “cd /” what is the difference? [duplicate]

Possible Duplicate: unix, difference between path starting with '/' and '//' If I make a cd // followed by a pwd I see: # cd // # pwd // why is that? what's the differece ...
5
votes
5answers
242 views

Is there a way to see the permissions of all the intermediate directories of a path..?

I have a file path.. Is there any single command to see the file/directory permissions of all the intermediate directories in the path..?
3
votes
2answers
775 views

Wrapper program that sets signal handler

I would like to have a wrapper program that runs a given command and sets a signal handler so that it gets run when the command receives a specified signal. The question is this: Is there an ...
3
votes
3answers
10k views

How to calculate values in a shell script?

I run this command in the terminal: grep "bla bla blah" blah* | echo "Blah: $(wc -l) / $(ls | wc -l) * 100" And I get this output: Blah: 44 / 89 * 100 What I expect to see: 49.4 Is there a ...
19
votes
4answers
10k views

How do I exit a script in a conditional statement?

I'm writing a bash script where I want to exit if the user is not root. The conditional works fine, but the script does not exit. [[ `id -u` == 0 ]] || (echo "Must be root to run script"; exit) ...
3
votes
1answer
1k views

“Permission denied” when starting binary despite “rwx” priviledge

I am trying to run the statistics software Stata 11 on Ubuntu 11.10. as a regular user and I get the following error message: bash: xstata: Permission denied The user priviledges seem ok to me as a ...
9
votes
3answers
690 views

How to pipe the list of commands displayed by of “tab complete”?

When using commands in bash I like the double tab option to display the available commands. Some commands have more possible matches than others: Is there a way I can pipe the output of the double ...
4
votes
2answers
5k views

How to use 7z to archive all the files and directories (including hidden ones) in a directory?

Because of specifics of my archiving needs I am not comfortable with solid tar.gz archives and use 7z instead. I use the following command to do this: 7z a -t7z -m0=lzma -mx=9 -mfb=64 -md=32m ...
1
vote
1answer
2k views

.bashrc doesn't get executed

I have a user (non-root) which has a ~/.bashrc file with some aliases in it. But it doesn't look like the file is executed at log in time. If I do source ~/.bashrc then it does what it's supposed to. ...
6
votes
4answers
653 views

Run a Command and then Parameter Substitution in one line

bash# hostname host1.example.com I only want host1. So: SHORT_HOST=$(/bin/hostname) SHORT_HOST=${SHORT_HOST%%.*} Can I turn this into a one liner? - or - what is the best way to make $SHORT_HOST ...
8
votes
1answer
618 views

What is the general format of keyname for key bindings in “inputrc” file?

I understand that the format for key bindings in inputrc file is: keyname: function-name or macro For keyname, I saw things like: "\e[B" "\e[1~" "\e[5D" "\M-l" "\C-[OD" "\e\e[D" What is the ...
3
votes
3answers
3k views

What are the significant differences between different shells? [duplicate]

Possible Duplicate: What are the fundamental differences between the mainstream *NIX shells? If I write a shell script in bash, will it run in ksh as well? if not, what are the ...
7
votes
2answers
690 views

How to use the SVN CLI effectively

How can I make myself more productive with the SVN CLI? I need to complete repetitive tasks like these: find modified files in directory commit only SOME of them selecting them somehow other then ...
2
votes
3answers
3k views

Bash string replace multiple chars with one

I'm replacing, from a feed title, all chars except letters and digits with a dash to use the result as a safe filename for any filesystem: $ t="Episodie 06: No hope of riding home (NEW) - Advanced ...
11
votes
3answers
831 views

Two commands, one pipeline

I need these two commands to be one (so I can pipe them further): dig +nottlid -t any bix.hu | egrep -v "^;;|^;|^$" | sort dig +nottlid -t any www.bix.hu | egrep -v "^;;|^;|^$" | sort I mean I ...
-2
votes
2answers
323 views

How to delete the second column from this input?

INPUT bix.hu. 42433 IN A 193.239.149.1 bix.hu. 42433 IN MX 10 deneb.iszt.hu. bix.hu. 42433 IN NS ns.iszt.hu. bix.hu. 42433 IN NS ns.iszt.hu. bix.hu. ...
5
votes
1answer
214 views

Any cd shortcut to switch an intermediate directory in current path?

if I have current path as a long one..and I want to switch to a directory with just one word from path replaced by something else..like say when using maven , I want to switch from main path to test ...
-1
votes
1answer
195 views

Timer in bash script not accurate when using it with longer times

#!/bin/bash # get user input ZENITY1=$(zenity --entry --text ' 1m: 60s\n 5m: 300s\n10m: 600s\n15m: 900s\n20m: 1200s\n25m: 1500s\n30m: 1800s\n35m: 2100s\n40m: 2400s\n45m: 2700s\n50m: ...
4
votes
3answers
13k views

Bash Sudo Command Not Found

I have set up a VM using turnkey linux redmine and I'm trying to SSH into the server to install some more items. It doesn't appear to be recognizing the sudo command. Every time I try to sudo ...
8
votes
2answers
5k views

How to insert a new line after every second line?

sed/bash/wharever :D INPUT: sadf asdf yxcv cxv eqrt asdf OUTPUT: sadf asdf yxcv cxv eqrt asdf
5
votes
2answers
295 views

Display Non-Zero Return Status in PS1

I want to include the return status in my prompt. (Easy add '$? ', right?) However, I only want the status returned (and trailing space) if non-zero. Example: sd ~ $ false 1 sd ~ $ true sd ~ $
2
votes
2answers
451 views

Function to evaluate variables in BASH

Given a variable name is there a function that will print its value? Often times I pass the name of a variable to a bash function and instead of doing the expansion while passing it I would like to ...
4
votes
3answers
16k views

Set a network range in the no_proxy environment variable

I'm in a network using a proxy. I've got machines using lots of scripts here and there accessing each other over HTTP. The network is 10.0.0.0/8. My proxy is 10.1.1.1:81, so I set it up accordingly: ...
7
votes
2answers
11k views

How to alter PATH within bash script?

I have several projects that require me to change versions of Java/Grails/Maven. I'm trying to handle this with some Bash scripts that would make the changes. For example: #!/bin/sh export ...
1
vote
3answers
341 views

ksh cannot cp from location with space in it?

I am trying to do the following in ksh but keep getting cannot stat message for the cp command: JMX_ROOT=/bfs-build/build-info/mep_mainline-Linux.latest/core/mainline/automation ...
1
vote
1answer
541 views

How can I make custom key bindings work even while SSH-ed into another machine?

I've added "\eOD": backward-word "\eOC": forward-word to my .inputrc to get ctrl-arrow key mappings sorted out in Cygwin allowing me to move forward and back fine. When I SSH to any other Linux ...
6
votes
2answers
630 views

How would I sort these directory names numerically?

I'm aware that I can somehow sort this output numerically (so cpu1/ follows cpu0/) ... I could probably get something to work eventually by splitting up the string various ways with awk, but is there ...
2
votes
2answers
412 views

Simple wrapper scripts spawning 100s of bash processes

I have this kind of GCC multilib wrapper set up: #file: gcc #!/usr/bin/env bash gcc -m32 "$@" which essentially just wraps a 64-bit multilib gcc to act as a non-multilib 32-bit gcc. When I build ...
5
votes
1answer
514 views

Pipes vs process substitution

While trying the cat "$@" trick to read from either standard input or given files, it turned out that pipe and process substitution handle a missing trailing newline differently: printf %s foo > ...
0
votes
1answer
396 views

Bash script doesn't TEE output to subdirectory

I've got a script that runs a number of curl commands by reading an input file line by line (each line has different curl parameters). I'm trying to tee the stnd out and stnd error of the curl ...
18
votes
1answer
20k views

For loops in zsh and bash

I have noticed there are two alternative ways of building loops in zsh: for x (1 2 3); do echo $x; done for x in 1 2 3; do echo $x; done They both print: 1 2 3 My question is, why the two ...
2
votes
4answers
3k views

Increment number in bash variable string

VERSION="4.0beta12" NEXT_VERSION=????? Writing an automatic release script, I have the current version in a variable $VERSION, and I would like to calculate the next version as $NEXT_VERSION. Rule: ...
29
votes
4answers
66k views

What is the “eval” command in bash?

What can a man do with the "eval" command, why is it usefull? It's some kind of built-in function in bash? There is no "man" page for it..
2
votes
1answer
642 views

How to read a hexdump byte by byte in bash or awk?

This is the hexadecimal output of an IPv6 TCP packet captured with tcpdump: 6000 0000 0018 0620 0000 0000 0000 0000 0000 0000 0000 0001 0000 0000 0000 0000 0000 0000 0000 0002 *0026 0026 0000 ...
3
votes
1answer
577 views

grep and brackets in text

I store downloaded files in a log like this: [source] filename To avoid downloading a file more than once I grep for [source] filename before: if ! grep "$signature" downloaded.log > ...
14
votes
5answers
5k views

How can I get bash to exit on backtick failure in a similar way to pipefail?

So I like to harden my bash scripts wherever I can (and when not able to delegate to a language like Python/Ruby) to ensure errors do not go uncaught. In that vein I have a strict.sh, which contains ...
2
votes
4answers
3k views

How to limit the number of lines a command's output has available in bash?

I started downloading a big file in the background using $ nohup wget http://example.tld/big.iso & which also gives me a nohup.out file that includes the output of wget. Now, if I later want ...
7
votes
2answers
7k views

Refresh aliases after defining new command

When I define new alias in .bash_aliases file or new function in .bashrc file is there some refresh command to be able immediately use the new aliases or functions without closing terminal (in my case ...
5
votes
2answers
667 views

Can a home directory have both .cshrc and .bashrc files?

Or are they both not allowed at the same time?
19
votes
7answers
8k views

Can I “export” functions in bash?

source some_file some_file: doit () { echo doit $1 } export TEST=true If I source some_file the function "doit" and the variable TEST are available on the command line. But running this script: ...