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
94 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
864 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
3k 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 ...
7
votes
2answers
398 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 ...
8
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
200 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
147 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 ...
39
votes
3answers
21k 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
123 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
220 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
308 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
791 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
321 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 ...
2
votes
0answers
688 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
289 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
106 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.
1
vote
3answers
233 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
335 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
576 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
260 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
140 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
86 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
862 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 ...
3
votes
3answers
2k views

How to convert all .wav files in subdirectories to .aac using neroAacEnc?

I have a collection of music in .wav format, and would like to convert it to .aac/.mp4 using neroAacEnc. How do I do this? I am using Arch Linux x86_64 and Xterm.
8
votes
0answers
213 views

how to get exit status from the command before the last [duplicate]

I have solaris machine ( solaris 10 ) please Look on the following simple commands (haconf -makerw | grep -iq "Cluster already writable") # haconf -makerw VCS WARNING V-16-1-10364 Cluster ...
5
votes
3answers
672 views

difference between .* and * in regular Expression

I've a file named "test" that contains linux Unixlinux Linuxunix it's linux l...x now when i use grep '\<l.*x\>' , it matches : linux it's linux l...x but when i use grep '\<l*x\>' ...
2
votes
2answers
74 views

xinput - Ctrl+<Left> misbehaves if history-search-backward is mapped

I am using these lines in my ~/.inputrc: "\e[5~": history-search-backward "\e[6~": history-search-forward With these settings when I type c on the prompt and do a PageUp, bash only shows command ...
5
votes
1answer
268 views

Execute multiple bash commands on the output of find

I want to execute some commands using the find -exec option, but I'm not sure what' wrong with this code. Currently, it's only processing the first find result, then getting stuck. I'm using bash in ...
1
vote
2answers
242 views

What does the -c option of sg do?

What does the -c option of sg do? At least on my machine, the man page fails to explain this option.
2
votes
3answers
4k views

Using bash shell function inside AWK

Is it possible to use bash function inside AWK somehow? Example file (string, int, int, int) Mike 247808 247809 247810 Trying to convert values from decimal to hexadecimal. Function defined ...
2
votes
6answers
2k views

sort ls output by users

On Linux, is there a way to sort ls output by users? What I try to achieve is something like this: user_a   file1 user_a   file2 user_b   another_file user_c   this_file user_c ...
10
votes
5answers
709 views

How to detect from script when the user's desktop is loaded?

I have a deamon, implemented in bash and running by means of cron and the @reboot option, that shows the desktop in inactivity. The script is as following (timings are short for testing purposes): ...
3
votes
2answers
14k views

How to avoid the need to issue “y” several times when removing protected file

I'm looking for a solution to be used as a response to "rm: remove write-protected regular file [x] ?" I was thinking of issuing a character followed by carriage return for several amount of times, ...
6
votes
3answers
7k views

Count number of lines of output from previous program

I'm trying to count the number of lines of output a certain program produces. The problem is, the program takes a long time to run, and I want to display the output to the user. Is there a way to ...
1
vote
0answers
148 views

rsstail Not Printing Output

I've installed rsstail 1.8 on my linux box and everything seems to be going smoothly, knock on wood, except for the part where rsstail isn't printing the streams. Running the command, I see that it's ...
4
votes
1answer
1k views

Pass colors from ls through pipe to awk 'print' statement

This is a follow-up to my question from yesterday, Show sum of file sizes in directory listing. Thanks to Zero Piraeus and a point in the right direction by Mauritz Hansen, I now have function ...
1
vote
1answer
389 views

Guide/help using Dialog with bash scripting

While I understand how to create menus, no guide I've found teaches how to actually link them to commands I was hoping to have something like: dialog--clear --title "n00b's spellbook" \ ...
4
votes
3answers
372 views

Why should 'Character Classes' be preferred over 'Character Ranges' In Shell (Bash)?

The Linux Command Line (Book - page count 47) says: ... you have to be very careful with them [character ranges] because they will not produce the expected results unless properly configured. For ...
0
votes
1answer
404 views

svn backup bash script errors

I have created bash script for create dump of svn repositories. I want to add such functionality that after dump of every repository script send it to remote server using rsync and delete from dump ...
12
votes
10answers
40k views

Show sum of file sizes in directory listing

The Windows dir directory listing command has a line at the end showing the total amount of space taken up by the files listed. For example, dir *.exe shows all the .exe files in the current ...
1
vote
0answers
3k views

Using sshpass, return code (exit status) differs for reasons unknown using valid commands

There are a few things going on here but I think ultimately, either CLish or SSH is returning an exit code that is messing up my work flow. I'm attempting to connect to a remote machine (CLish shell) ...
2
votes
5answers
364 views

Command substitution - single quotes and spaces

How can I make command substitution pass a list of single-quoted POSIX paths separated by spaces? command1 $(command2) command1 '/path/to/file 1' '/path/to/file 2' '/path/to/file 3' How can I trace ...
3
votes
1answer
62 views

Is there an easy way to change bash suggestions?

I've noticed that some console commands (like sudo or xargs) are using different kind of suggestions when I press Tab (they suggest programs instead of files). Is there a way to mimic that kind of ...
0
votes
2answers
116 views

Supress expansion of * in echo

I am working on a script which dynamically executes some queries on daily basis. These queries are coming from a table in the database. Here is the sample output of the query table: ...
-1
votes
1answer
1k views

zsh: Is it worth the switch from bash? Is it the time? [closed]

I have been a bash user for years now. However, I find that zsh is increasingly gaining momentum. I came up with the following questions: Is zsh really becoming that popular? Will it compete with ...
3
votes
1answer
345 views

bash: different output between CTRL-C vs “ordered cleanup”

I really tried to find a better title for this question. I am open for suggestions. I've written a bash script that traps EXIT and calls a function if that signal is received. It calls the same ...
1
vote
2answers
270 views

How to print shell variables and values to be able to copy/paste them?

In Bash 4.2.25, the set and env output is not escaped, so shell escapes and any non-printable characters won't be copy-pasteable. Take for example this shell session: $ export foo=$'a\nbar=\baz' $ ...