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
1answer
236 views

Why is the following command killing a system?

Anyone understand the following code , running in bash ? :(){ :|:& };: It seems to be a "fork" bomb on Linux.
1
vote
1answer
202 views

Tab and complete

Is the key binding for tab to complete in the readline settings set implicitly. Because when I outputted bind -q complete I got this in return complete can be invoked via "\C-i", "\e\e". ...
2
votes
0answers
295 views

What happens when you background a function which calls another function?

Question says it all on the tin. Can someone explain to me what goes on here ? I'm trying to find out how to background a process in a script that calls another function and reliably terminate it when ...
1
vote
1answer
435 views

How to demux audio and know what type it is?

How to demuxed audio and know what type it is? When muxing an audio into a video, ffmpeg, mencoder, etc require to know what the audio's encoding is. The encoder typically uses the file name's ...
5
votes
2answers
657 views

Setting readline variables in the shell

I read in the man page, that you set readline parameters on an off or to a value by using set var value Is this the same as the set builtin, and how do you set the variables once inputrc has already ...
18
votes
4answers
26k views

What does ` (backquote/backtick) mean in bash?

I came across the following command sudo chown `id -u` /somedir And I wonder what is the meaning of the ` symbol. I noticed for instance that while the command above works well the one below does ...
8
votes
3answers
10k views

Bash - test for newline?

In various places around the web I've found: \015 \012 \x0a - hex \n \r all as synonyms for various newlines / carriage returns... But in this small script I cannot recognise when I come across a ...
2
votes
4answers
903 views

Bash options and interactive shells

The -s option to bash doesn't seem to really do anything When I execute commands with or without it nothing changes. What really confuses me is when I execute a shell script I always seem to be ...
1
vote
2answers
209 views

conditional expression and expansion

I don't seem to understand how to "test" the conditional operators [[ and [. I tried using various form such as echo [[a=a]] [[a=a]] echo $? and some other things I want to see what they ...
8
votes
4answers
9k views

How do I reverse a for loop?

How do I properly do a for loop in reverse order? for f in /var/logs/foo*.log; do bar "$f" done I need a solution that doesn't break for funky characters in the file names.
2
votes
2answers
279 views

Why does “$i | sed” not work?

I have this code: if [ $i | sed -e "s/^.*\(.\)$/\1/" = "/" ] then echo "folder" else echo "file" fi where $i is something like this app4/ The code above should get the last char of the ...
2
votes
1answer
339 views

Get pid of long running command executed via at

I would like to spawn a persistent netcat server. My command of choice is the following: echo "bash -c \"while [ 1 ]; do nc -l -p 1111 >> check; done\"" | at now I am wondering how I can get ...
-2
votes
1answer
268 views

Why does this script show all files in the directory and not just PDF files?

I wrote the script below to find the number of PDF files in a given directory. However, it instead shows all the files in the directory: #!bin/bash message="." message1="*.pdf" ls -al $message ...
3
votes
3answers
700 views

Is it a script or is it a binary?

At the end, it looks like it's just a regular sh script: [USER@MACHINE ~/Desktop/D] head -2 truecrypt-7.1-setup-x86 #!/bin/sh CHECKSUM=163123652 but @the scripts end: [USER@MACHINE ~/Desktop/D] ...
2
votes
2answers
1k views

Is the `\` character escaping or becoming part of my ssh key password

If I do: ssh-keygen -N password123\$ -f bobskeys Is \ escaping the $ character or becoming part of the password? Or rather, will bash be doing any escaping before ssh-keygen gets the password ...
5
votes
2answers
2k views

Is it possible to get the error message from previous command which failed when the conditional command runs using ||

I have a helper function: function error_exit { /opt/aws/bin/cfn-signal ... exit 1 } This helper function is used to signal an error. Here is an example of usage: /opt/aws/bin/cfn-init -s ...
3
votes
1answer
587 views

wait for autossh connection to complete

I'm trying to create a script that runs a few commands that take a long time to execute and require a constant connection, but autossh user@server wait $! #or wait ${!} commandA commandB doesn't ...
0
votes
1answer
620 views

-bash: command: command not found [closed]

I'm trying to run a program from the command line, and I got a -bash: command: command not found error. What can I do to troubleshoot/fix the problem?
11
votes
4answers
11k views

Script to change current directory (cd, pwd)

I want to run a script to simply change the current working directory: #!/bin/bash cd web/www/project But, after I run it, the current pwd remains unchanged! How can I do that?
2
votes
0answers
109 views

How do I get this Bash-script to work? [duplicate]

Possible Duplicate: How to name a file in the deepest level of a directory tree How do I get this script to work? The goal is to find the directory at the deepest level in the directory ...
2
votes
2answers
935 views

su - username -c “./script.sh” -> no such file or directory

We have: a user nico. a folder /home/nico/script_home with some bash scripts: main.sh subscripta.sh sqlscripta.sh We connect as root and cd /home/nico/script_home/ Finally we run ./main.sh We ...
13
votes
5answers
10k views

#!/bin/bash - no such file or directory

I've created a bash script but when I try to execute it, I get #!/bin/bash no such file or directory I need to run the command: bash script.sh for it to work. How can I fix this?
6
votes
1answer
482 views

“Safe mode” on Linux?

Under RouterOS/Cisco there is a function called "safe mode". When someone presses CTRL+X then the terminal goes in "safe-mode" that meant that if the terminal exists in a "bad way", ex.: the user ...
2
votes
1answer
2k views

Script to SCP files works manually but not through cron

I'm using CentOS 5.6. The below code might have some typos as I needed to change real info to fake info for security reasons: backup.sh #!/bin/bash set -vx rm -v /server/temp_db.gz rm -v ...
2
votes
6answers
1k views

How to name a file in the deepest level of a directory tree

How do I name one random file in the deepest level of a directory tree using basic Bash commands and script? I was searching for a way to do it as an one-liner and without functions. Assuming also ...
6
votes
4answers
3k views

Displaying seconds as days/hours/mins/seconds?

Is it possible to easily format seconds as a human-readable time in bash? I don't want to format it as a date, but as the number of days/hours/minutes, etc...
3
votes
5answers
286 views

evaluate multiple patterns from program output and write into pattern specific files

I have a script outputting some value/numbers and I want to split those into two files. I am looking at something like: ./runme.sh | grep 'ook' >> ook.out | grep 'eek' >> eek.out Where ...
3
votes
1answer
71 views

Calling a script on each line of a file

I have a bash script that takes 3 arguments: $ do_something foo bar baz and a file with several lines, each with different 3 args. I want to execute the script as a cronjob, and each time it's ...
2
votes
2answers
2k views

How to fix this error? make: *** [obj/local/armeabi/libgstaudioflinger.so] Error 1

I am trying to install this following framework from my Linux Fedora box to Android using there SDK/NDK. But after following all instruction its getting still failed to get build. Any idea how to fix ...
1
vote
1answer
695 views

grep searchstring /etc/crontab strange behavior in BASH script

I am working on a BASH script which creates automated backups via the crontab. I am trying to use myVARIABLE=`grep backup /etc/crontab` to return lines containing "backup" if an entry has already ...
0
votes
1answer
718 views

POSIX and Bash, sh shorthand, for compound if statement

I prefer to do my sh commands in shorthand, And I prefer to be in POSIX. Truthfully, if the script can run on Dash, that is good enough. Which means using the test command [, not the extended [[. I ...
8
votes
4answers
2k views

Abbreviated current directory in shell prompt?

vim has a really nice feature which it utilizes in its paths when they're a bit long: It abbreviates the path to the document in the tab at the top. Is there a way to do something similar to this ...
2
votes
1answer
640 views

Redirecting output when I execute “bash -c …” from a C program

Say I have a C program and in it I want to execute a shell command and redirect its output to file, by using the stdlib system function. system("bash -c \"echo $HOME\" > a.txt"); Now this is for ...
13
votes
10answers
2k views

“Bookmarks” for bash

Navigating several layers of nested directories is often a pain. On Firefox, it is easy because they have bookmarks. So what I'd like to do to bookmarks a file is to type: $ go --add classes ...
10
votes
1answer
1k views

Readable comments on separate lines in a multi-line bash command with pipelines?

When creating shell scripts using pipelines, and using the backslash to continue lines, I want to insert comments on separate lines, in a robust, readable and portable fashion. For example, given ...
2
votes
1answer
3k views

How to set a new password from bash?

I'm using busybox with a limited passwd (I don't have --stdin option) and without chpasswd and I need to change the password of an user from bash. Here is my best result: echo newpassword > ...
1
vote
2answers
815 views

autocomplete filenames using compgen

As part of a larger autocomplete function I'm writing, I want to use compgen to generate a list of files. I read the bash manual entries for compgen and complete, and from there I assumed that the ...
10
votes
2answers
19k views

Refresh env variables after editing bashrc file

I frequently edited the .bashrc file to export new environment variables. Rather than close the console and start a new one to refresh the env variables, is there a convenient way to refresh?
12
votes
1answer
7k views

How do I set a user's default .bashrc file?

On Ubuntu 10.4 I have edited the /etc/bash.bashrc file to set some variables like the command history size (HISTSIZE=5000), however if I create a new users Ubuntu by default gives them a .bashrc file ...
11
votes
4answers
17k views

How to read from two input files using while loop

I wanted to know if there is any way of reading from two input files in a nested while loop one line at a time. For example, lets say I have two files FileA and FileB. FileA: [jaypal:~/Temp] cat ...
18
votes
4answers
13k views

How to delete line with echo?

I know that I could delete the last three chars with: echo -ne '\b\b\b' But how can I delete a full line? I mean I dont want to use: echo -ne ...
9
votes
3answers
4k views

How to /dev/null background processes “informational” output?

[USER@SERVER ~] sleep 3 & [1] 5232 [USER@SERVER ~] [1]+ Done sleep 3 [USER@SERVER ~] How do I /dev/null these two messages?: [1] 5232 [1]+ Done sleep ...
6
votes
2answers
288 views

Send task to background in an “if”

Why is this? if true; then sleep 3 &; fi bash: syntax error near unexpected token `;' I want to run sleep 3 in the background so that the command ["sleep 3" is just an example] would run ...
3
votes
1answer
485 views

How can I copy all users .bash_history files into my home directory?

I am running as root. I want to copy all the users on the system's .bash_history files into my home directory. I can do this to combine all of them into one, but then I can't tell who's commands are ...
2
votes
1answer
2k views

Why my $PATH is not inherited by the invoked bash?

I work on an AIX system where I have no administrator privileges. It has several shells installed, default being tcsh. I am not allowed to change the login shell. Usually I start my session from exec ...
6
votes
4answers
2k views

Colored FIND output?

Is it possible to get colored output from the find command? That is, in the path of each found item, directories are blue, executable scripts are green, et cetera? I'm using version 4.4.2 of GNU ...
11
votes
2answers
6k views

How are parenthesis interpreted at the command line?

While reading up on how to set up grub, one article mentioned that I need to use a syntax like echo \(hd0,0\) >> /boot/grub/grub.conf or echo '(hd0,0)' >> /boot/grub/grub.conf ...
127
votes
4answers
218k views

How to correctly add a path to PATH?

I'm wondering where a new path has to be added to PATH environment variable. I know this is accomplished editing .bash_rc (for example), but it's not clear how to do this. This way: export ...
1
vote
1answer
892 views

How to put a command's result into a variable? [duplicate]

Possible Duplicate: Storing output of command in shell variable Can anyone advise please how can I put the result of jps | awk '$2~/Bootstrap/{print $1}' into a variable so that I can use ...
9
votes
2answers
3k views

Parallelizing a for loop

I want to parallelize the for loops of the following code. How to do this? #!/bin/bash N=$1 n=$2 for (( i=1; i<=$N; i++ )); do min=100000000000000 //set min to some garbage value for (( ...