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

1
vote
1answer
452 views

Bash script to hide/show files

I prepared a little bash script to toggle the visibility of my hidden OS X files. if (defaults write com.apple.finder AppleShowAllFiles FALSE); then defaults write com.apple.finder ...
1
vote
1answer
286 views

Why is yum's tab completion slow?

Why is yum's tab completion slow? Is it because it needs to connect to the internet? If yes, how can I disable that?
1
vote
0answers
22 views

Fedora's command-not-found doesn't work [duplicate]

I've recently installed Fedora 19. Packagekit-command-not-found is installed. But it's own examples doesn't work. When I enter gedti the output is: bash: gedti: command not found... Similar command ...
2
votes
1answer
1k views

Fedora's command-not-found doesn't work

I've recently installed Fedora 19. Packagekit-command-not-found is installed. But its own examples don't work. When I enter gedti the output is: bash: gedti: command not found... Similar command is: ...
3
votes
1answer
484 views

Use time ,timeout and ulimit commands properly

I'm running a command in CentOS and at the same time I want to do 2 things: write the run time of the command to a file and set a time limit which stops the command I implemented the first one ...
0
votes
0answers
305 views

Unable to autocomplete ONLY when typing a make command

I'm running Ubuntu Linux 10.04. And I have the following in my .bashrc file: if [ -f /etc/bash_completion ] && ! shopt -oq posix; then . /etc/bash_completion fi I'm having a problem ...
1
vote
2answers
327 views

add server name before filename with uname -n

Here is my command in my script: mv -f -v $oldfile /infanass/dev/admin/backup/${oldfile##*/}_$(date +%F-%T) Right now the output is: file1.txt_2013-07-11-15:08:16 I want the server name to show ...
2
votes
1answer
323 views

How can I work around the program failing if there is *any* stdin?

For example, the following works fine: /usr/bin/program It produces some output, and gets to result. But if I invoke it like this: echo -n | /usr/bin/program or this echo -n | bash -c ...
6
votes
3answers
14k views

bash script error stty: standard input: Inappropriate ioctl for device

I'm using here-documents in a bash script to automate installation and setup where a password is required many times. I enter the password once and the script passes it to the various commands. In ...
1
vote
1answer
7k views

Adding a time stamp when moving a file in bash [duplicate]

#!/bin/bash while read server <&3; do #read server names into the while loop if [[ ! $server =~ [^[:space:]] ]] ; then #empty line exception continue fi echo "Connecting to - ...
3
votes
2answers
2k views

How to prevent command injection through command options?

I have an wrapper application where I need to let the user specify custom options to pass to a simulator. However, I want to make sure the user doesn't inject other commands through the user options. ...
4
votes
3answers
801 views

Put text in the bash command line buffer

I would like to programmatically put a certain piece of text in the command line buffer of bash, read to be edited and used as a command. What I am looking forward to is something similar to read -i ...
0
votes
1answer
315 views

problem reading and comparing files using nested loops [closed]

while read newfile <&3; do if [[ ! $newfile =~ [^[:space:]] ]] ; then #empty line exception continue fi # while read oldfile <&3; do if [[ ! $oldfile =~ [^[:space:]] ...
1
vote
3answers
4k views

Count number of lines with a certain value in a column for all files in directory recursively

I have 40 files in a directory and I want to count the number of times there is a line with a "2" in the first column in each file individually. I am trying something like this, but it prints out ...
8
votes
3answers
5k views

Loop through the lines of two files in parallel [closed]

The object of the script I'm making is to compare two series of files. The file names are themselves stored into two separate files, one path per line. My idea is to have two while read loops, one for ...
0
votes
2answers
8k views

Read the output of a command into a variable [duplicate]

I am making a bash script but I'm totally new and got lost. I've made this code cat * | grep "|*parameter1*|" | grep "|*parameter2*|" | cut -f 8,11,12,15,21,23,34 -d "|" | wc -l which works just ...
0
votes
2answers
558 views

How does strace know to use /bin/echo instead of failing on a built-in

When I do strace echo hello, I see it is using /bin/echo, but built-in echo should be found first. Is it a functionality of strace to skip built-in commands? strace -- version 4.5.19 I understand ...
4
votes
2answers
613 views

When wouldn't one want `cp` to be recursive?

Under what conditions might one wish to use the cp command on a directory yet have it not be recursive? Consider: $ tree . └── old └── inner └── a.txt 2 directories, 1 file $ cp ...
4
votes
1answer
143 views

History of commands and directories we were in

I was wondering: If I type history I can see the previous commands I typed and see what happened and perhaps keep commands as reference. But I don't know in which directory I was when I typed the ...
3
votes
2answers
144 views

Bash expansion of ${@} as command

I have a parent script while read cmd do nohup ./script ${cmd[@]} &>> log & done < ~/list that executes this child script while true do eval "${CMD[@]}" #${CMD[@]} ...
14
votes
4answers
15k views

How can I tell what command an alias stands for?

ll is a common alias in many Linux distros. How can I tell what it aliases to? I've tried checking my .bashrc, but I am not able tell what ll is equivalent to.
4
votes
2answers
1k views

SSH tunnel through middleman server - how to connect in one step (using key pair)?

My question is basically how to turn my existing two steps into one step. I have a working SSH tunnel set up between two computers using a middleman server like this: ...
14
votes
4answers
5k views

How to make bash abort the execution of a script on syntax error?

To be on safe side, I'd like bash abort the execution of a script if it encounters a syntax error. To my surprise, I can't achieve this. (set -e is not enough.) Example: #!/bin/bash # Do exit on ...
3
votes
3answers
432 views

Quick access to work directory of background job

Minimal effort to reproduce what I am looking for, is as follows /$ sleep 1h & [1] 6564 /$ cd ~$ jobs [1]+ Running sleep 1h & (wd: /) When I use jobs to manage my ...
3
votes
5answers
572 views

How can I split a pipe into 16 byte sequences?

I'm writing a bash script to automate the decryption of a certain file; however the file is encrypted in 16 byte blocks, rather than simply encoded in its entirety. Here's some psuedo code to briefly ...
2
votes
2answers
692 views

Having multi lines in bash command substitution

I have a very long bash command inside a command substitution like following: $( comaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaand ) I want to know if there is a way to break this command into shorter ...
3
votes
2answers
9k views

How to return the exit code? Error: return: Reading: numeric argument required

Here's a simplified version of my script. My question is, How do I return the exit code from apt-get in this case? #!/bin/bash install_auto() { apt-get -h > /dev/null 2>&1 if [ $? -eq 0 ] ; ...
6
votes
3answers
273 views

How to create merged input (stdin) for a program

Consider such script: echo a echo b echo c It will produce 3 lines and now I can run it like this: abc_script | real_program real_program will get in its input those 3 files. However, there is a ...
4
votes
1answer
183 views

How to concat file and a line on-fly?

I would like to send to the stdout entire file + extra line. How to do this nicely? So far I did: for LINE in $(cat $INPUT_FILE) do echo $LINE done echo $EXTRA_LINE How to do this bash way (for ...
3
votes
1answer
853 views

Bash: slice of positional parameters

How can I get a slice of $@ in Bash without first having to copy all positional parameters to another array like this? argv=($@) echo ${argv[@]:2};
3
votes
1answer
3k views

How to use zypper in bash scripts for someone coming from apt-get?

I have a few questions about moving from apt-get to zypper in bash scripts. What is the equivalent of this? sudo apt-get install curl --assume-yes (where curl could be any package) I found the ...
1
vote
2answers
1k views

How can I make “bind” command to work in sh shell

How can I make the next script to run when I'm using sh shell: #!/bin/bash bind '^[[3'=prefix-2 bind '^[[3~'=delete-char-forward bind '^[[1'=prefix-2 bind '^[[1~'=beginning-of-line bind ...
3
votes
2answers
818 views

Bad substitution inside xargs subshell?

I'm using this command to process PNG files: find . -iname "*png" -print0 | xargs -r0 --max-procs=4 -n1 sh -c 'pngnq -s1 $1 && advpng -z -4 -q ${$1%.*}-nq8.png' - It seems to actually work ...
3
votes
1answer
3k views

Executable symbolic link file not working

On Mac OSX, I am having trouble with a pretty simple thing. My symbolic link doesn't want to execute. Can you help me spot the trouble? Thanks! $ echo $PATH ...
0
votes
2answers
903 views

Redirect all stderr of a console and subsequent commands to a file [duplicate]

I know how to redirect stderr to a file or to the stdout when I issue a command: command 2 > log or command 2 > &1 or even command 2 > &1 > /dev/null. However, I want to redirect ...
1
vote
1answer
361 views

difference between bash, -bash and /bin/bash in ps output [duplicate]

Someone had spawned a while true loop in bash (logged in as root) on a server. It kept spawning processes, which fortunately exited but I needed to kill the parent. I came to know it was spawned ...
7
votes
1answer
157 views

The shell's “delete word” shortcut deletes too many characters

Under Bash some behavior of Alt+d has been driving me crazy since years and I figured out that maybe it could be fixed with a setting. If I'm at a terminal and issue a command like this: ...$ cat ...
5
votes
1answer
658 views

command substitution handling in fish vs. other shells (sh, bash, zsh)

The program mc (Midnight Commander) is not intended to be used for command substitution, but I would like to know why different shells behave differently when this program (and it seems like other ...
1
vote
1answer
152 views

Where is the Ctrl+/ (^/) bash shortcut for undo defined?

I can not find the mapping in bind -p nor in stty -a. Also, it only works in the terminal emulators I've tried (xterm, konsole, gnome-terminal) and not in the linux system console. I think it's ...
12
votes
8answers
4k views

How to remove multiple newlines at EOF?

I have files that end in one or more newlines and should end in only one newline. How can I do that with Bash/Unix/GNU tools? Example bad file: 1\n \n 2\n \n \n 3\n \n \n \n Example corrected ...
1
vote
1answer
399 views

Building Virtualbox Linux Headers

I am trying to get Virtualbox running on my Acer C7 with Ubuntu 13.04. I ran the script posted here but I am getting the following error after this point in the script. # make-kpkg kernel_image ...
1
vote
2answers
1k views

Mysterious bash instances using a lot of CPU, how can I debug?

I seem to have multiple bash processes running that are taking up most of my CPU. This is the output of top -c: PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 20116 ...
0
votes
1answer
33 views

Read files in Directory and take diff

I have two directories named comp1 and comp2 and both have files named file1 and file2. I need a bash script which read file1 from both the directories and take diff of each file and redirect to some ...
1
vote
3answers
1k views

Renaming or making filenames unique

I have written a plsql procedure using utl file to create files in the temp directory in Unix. I am sending the names of the files to a shell script to mail these files and delete after mailing from ...
17
votes
3answers
1k views

Run commands at random

I want to run one of the two commands C1 and C2 at random. How do I do that on commandline (bash)? Will appreciate if a one-liner is possible.
1
vote
1answer
59 views

How and where can I permanently set $ program file to have extra argument '&'

When I run a program from terminal like so: $ program file For example $ gedit myfile.txt I cannot think of a time when I would not prefer to use '&' so that I can free up my terminal ...
0
votes
2answers
725 views

Assigning a value with echo piped together with the bc command and using a variable as an argument

Basically i'd like to assign to variable $finalbyte a value (which consists of a binary representation of a byte e.g 11100000). So trying to do that i put the following as part of some script: ...
1
vote
4answers
1k views

how to replace a value with a calculation in bash/sed

I used bash sed to replace ip address in a group of files, i.e 10.1.1.x => 10.2.2.x-19: file1: 10.1.1.29 => 10.2.2.10, file2: 10.1.1.30 => 10.2.2.11, file3: 10.1.1.31 => 10.2.2.12, ...
0
votes
2answers
552 views

sed - replace complex lines in a file using variables

How do I replace a complex line in a file using sed? For example I want replace a udev rule in /etc/udev/rules.d/70-persistent-net.rules. This doesn't work: OLD_RULE='SUBSYSTEM=="net", ...
0
votes
1answer
1k views

Expression error in bash script

I am getting this really weird error despite of the fact that the same script runs fine on one platform (Arch linux) but not on my other mobile platform (Maemo Linux). I'll pass here the relevant part ...