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

0
votes
1answer
662 views

Directory diff in bash script

I have a bash script that expands two archives (jar files) into two directories and then does a diff of the two folders. I want the diff to be piped into a file so I do this in the bash file. diff -r ...
7
votes
1answer
2k views

Autocomplete of filename in directory

This question is quite similar to this one, but I can't understand the solution. I also know this tutorial, but still I am unable to understand what I am doing wrong. I am trying to autocomplete the ...
3
votes
3answers
484 views

Automatic cleanup of Bash history

How can Bash history be automatically cleaned up? For example Remove detectable typos from history (ls-lh does not show up in which, so it is removed, I meant to type ls -lh) Clean excessive spaces ...
2
votes
2answers
153 views

Bash completion for `unset` command

How can I setup bash completion for the unset command, like when you use echo $XXX, you can get a completion for XXX?
1
vote
1answer
1k views

Capture user input while doing other things

Is there a way to have the output of a subprocess (something other than 'sleep' below) be dovetailed with the output from a foreground command-loop? For example: while true do echo "updating ...
3
votes
3answers
2k views

Ignore or catch division by zero

How do I ignore the division by zero error in Bash? Example 1: (Doesn't work) echo $((1/0)); echo "yay"; echo $((1/0)) || echo "yay"; Example 2: echo -n $(echo -n $((1/0))) 2> /dev/null; echo ...
1
vote
4answers
1k views

Checking for the existence of files against a list

I have a "command" text file that issues a data file download command on each line. I send the command file to bash. However, a small percentage of the downloads fail. Here is the algorithm I ...
4
votes
4answers
577 views

Show output on another “screen” and return to normal when done

I want a similar behavior as less vim nano etc. uses. Is this possible to achieve with bash?
6
votes
1answer
3k views

How do I get the difference between two timestamps?

I am creating a simple backup script. I would like to have a message saying "You last backed up x days ago" on login. I can create a file when I do the backup "backup/.last_backup_timestamp" but what ...
17
votes
4answers
3k views

Is it possible to configure ctrl-w (delete word)?

Normally, Ctrl-w deletes back to the last whitespace. Is it possible to configure it to use additional characters, such as /? Edit: To be more clear: I don't want to configure the key for it, I want ...
8
votes
1answer
1k views

Why bash time is more precise then GNU time?

The buitin bash command time gives milisecond precision of execution and GNU time (usually /usr/bin/time) gives centisecond precision. The times(2) syscall gives times in clocks, and 100 clocks = 1 ...
11
votes
4answers
2k views

How do I choose specific files in a different directory using bash?

I want to list (or delete, or do some other operation) on certain files in a directory, like this: $ ls /opt/somedir/ aa bb cc aa.txt bb.txt cc.txt $ ls /opt/somedir/(aa|bb|cc) ## pseudo-bash ...
3
votes
3answers
4k views

After installing oh-my-zsh: … /.zshrc:source:34: no such file or directory … /.oh-my-zsh/oh-my-zsh.sh

I just tried to install oh-my-zsh. I get the following error when I try to run rvm: zsh: command not found: rvm I also get the following error when I try to open a new tab: ...
7
votes
3answers
572 views

Is there a shortcut in bash to delete the last segment of a path?

I've become pretty proficient with a number of bash shortcut keys that make my bash-ing faster: C-a/C-e, C-u, C-w, M-f/M-b, C-r etc. One common task that I haven't found a good shortcut for though is ...
1
vote
3answers
518 views

Customize the way stderr is appended to a file

I have an issue with a shell script that uses rsync to synchronize 2 directories. I'm storing the result of the rsync command (whether it's successful or not) to a file named status and in case there ...
3
votes
1answer
947 views

Remap bash vi keys?

I use Dvorak and vi, so when I found out about the vi mode in Bash, I was very excited. However, it would be even better if I could remap the movement keys to be the ones that I use in vi (I swap keys ...
5
votes
1answer
3k views

In Bash, why is PROMPT_COMMAND set to something invisible?

On RHEL6 and CentOS 6, /etc/bashrc sets PROMPT_COMMAND here: case $TERM in xterm*) if [ -e /etc/sysconfig/bash-prompt-xterm ]; then PROMPT_COMMAND=/etc/sysconfig/bash-prompt-xterm ...
3
votes
2answers
100 views

How to output only given chars?

How can I crop unneeded chars, and only output what I need? For example: input: ASDFQWER output: DFQ I mean in this case I need only the 3.-4.-5. chars of the string. How do I do that?
7
votes
2answers
630 views

How to do block selection in `screen`

In vim, there's a CtrlV to do block selection. How can I do it in screen?
6
votes
3answers
4k views

How to setup trap in bash functions?

I can setup trap in bash scripts but not bash functions. For example, source the code below and run f, now try Ctrl+C, it's not been trapped! How to setup trap in bash functions? 4 trap ctrl_c ...
5
votes
1answer
240 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
256 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
369 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
469 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
802 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 ...
32
votes
4answers
46k 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
13k views

How to discover a new line using a for loop?

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
1k 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
220 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 ...
12
votes
4answers
12k 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
364 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
399 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
288 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
983 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
2k 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
3k 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
664 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
691 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?
13
votes
4answers
19k 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
110 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
1k 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 ...
16
votes
5answers
25k 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
579 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
3k 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 ...
3
votes
6answers
2k 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 ...
10
votes
5answers
4k 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
358 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
74 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
863 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 ...