Bash is the shell from the GNU project. It is the standard shell on Linux and often available on other unices. If your question applies to all Bourne/POSIX-style shells, use the /shell tag instead.

learn more… | top users | synonyms

0
votes
2answers
34 views

Finding an elements in an array in bash

I am using the following code to first split an array into 2 and then search if 2 elements "Alchemist" and "Axe" are present in each of the two split arrays. tempifs=$IFS IFS=, match=($i) ...
5
votes
1answer
43 views

Save password in bash script for multiple queries

I would like to know if there is a safe way to only be queried for a password once in a custom bash script, and then save it somehow to be used for later needs. At the end of the script it should be ...
6
votes
4answers
452 views

Combined `mkdir` and `cd`? [duplicate]

is there any way (what is the easiest way in bash) to combine the following: mkdir foo cd foo The manpage for mkdir does not describe anything like that, maybe there is a fancy version of mkdir? I ...
2
votes
3answers
40 views

How to do more than one substring replace at once in bash?

I have a directory contains image files that are to be echoed in bash. While echoing, I want to replace both file name and extension in single line command. Example files: images/file_name_1.jpg ...
0
votes
1answer
21 views

understand the output of stty -a and change ctril backspace to just backspace

I am working in bash shell on a Solaris environment and whenever I type "backspace" it clears out the entire line. Do you have any suggestions for me to change the backspace clearing entire line to ...
4
votes
3answers
90 views

Dynamically trim stdout line width in Bash

Lately, I have been experimenting with the ps command, and sometimes long paths wrap to the next line (or two) and make it hard to read. I want to pipe the ps output into another program to limit the ...
2
votes
1answer
20 views

Get bash DEBUG trap to execute only once for and/or lists?

Suppose I set a trap on DEBUG like so: unset PROMPT_COMMAND # don't want $PROMPT_COMMAND triggering DEBUG trap trap 'printf %s\\n "most recent history line: $(history 1)" >&2' DEBUG If I do ...
-4
votes
1answer
41 views

-bash: -sudo: command not found [on hold]

Some dependencies were missing when I installed THC Hydra. I found this site: http://www.aldeid.com/wiki/Thc-hydra which directed me to install the missing package via this line code: sudo apt-get ...
2
votes
3answers
51 views

Compare two files for matching lines and store positive results [duplicate]

I have two files. File 1: A0001 C001 B0003 C896 A0024 C234 . B1542 C231 . upto 28412 such lines File 2: A0001 A0024 B1542 . . and 12000 such lines. I want to compare File 2 against File 1 ...
0
votes
2answers
41 views

ln -s with a path relative to pwd

I'm trying to create a bunch of symbolic links, but I can't figure out why this is working ln -s /Users/niels/something/foo ~/bin/foo_link while this cd /Users/niels/something ln -s foo ...
6
votes
2answers
982 views

what will ¬ do in bash?

While wanting to start gitg as backgrounded through writing gitg & I accidentally typed gitg ¬. This did not cause an error, instead I got with a later command in the same terminal (translated): ...
2
votes
2answers
17 views

Capture transcript of program with redirected input and output

A typical interaction for a program I've written might look like this: Enter command: a_command Completed a command Enter command: another_command Completed another command I typically run my ...
1
vote
3answers
27 views

Shell vi mode prints (arg: repetition): How to remove it?

Whenever you are in vi command mode on the shell and hit a number, like 8, "(arg: 8)" shows at the start of the line. Anyone know how to make it not do that? The moving the line I'm typing is ...
5
votes
2answers
153 views

How process substitution is implemented in bash?

I was researching the other question, when I realized I don't understand what's happening under the hood, what are those /dev/fd/* files and how come child processes can open them.
12
votes
5answers
334 views

Stateful bash function

I’d like to implement a function in Bash which increases (and returns) a count with every call. Unfortunately this seems non-trivial since I’m invoking the function inside a subshell and it ...
7
votes
6answers
601 views

Is it possible to remove folder prefix from a `ls` command

I am in a bash script and I want to get the list of all files (let say all jar files). I execute the command ls -1 lib/*.jar and I get the output: lib/mylib_1.jar lib/mylib_2.jar ... Is there any ...
4
votes
2answers
448 views

What does tail -f <directory name> do?

I mistakenly executed the following command in the terminal: tail -f /logs/applications/logs* I got the following output: tail: file shrunk! Error 0 I am not sure what exactly happened. I have ...
2
votes
2answers
34 views

Is it possible to generate a separate file list when creating a tarball?

When using tar for backups I'd like to create a separate list of the files that is included in the archive for storing alongside the backup tarball. Solutions that's not so good: tar --verbose ... ...
4
votes
2answers
110 views

Process substitution from curl to bash as root

I'm trying to run a script from URL as root with this command: sudo bash <(curl -s http://copy.com/gLVZIqUubzcS/popcorn) But I'm getting this error: bash: /dev/fd/63: Aucun fichier ou dossier ...
3
votes
1answer
34 views

Customize bash to always include a certain parameter

When using the "ls" command, bash prints in the following format: file1 file2 file3 file4 file5 file6 file7 file8 But when given the parameter "-1", it prints: file1 file2 file3 etc... Is there ...
0
votes
2answers
70 views

How do I run a command on a TTY from a SSH session?

Does anyone know of a way that I could run a command from my ssh session and have it display on tty1? It seems like I could do that like: script command >> /dev/tty1. However, if I were to do ...
4
votes
5answers
99 views

`ls -l` of a file and all the directories leading to it?

Before I start writing a (probably easy) script, is there a command that does the equivalent of the following one: [:~/software/scripts] % ls -ld / /usr /usr/bin /usr/bin/tee drwxr-xr-x 21 root root ...
4
votes
2answers
53 views

Script to loop through folders with numeric names

I am working on a bash script to compress the images in my Wordpress folders. The wordpress folder structure is as follows: > wp-content/uploads/2014/01/filename.jpg > ...
0
votes
0answers
11 views

Convert rgba color value to a Terminal supported color

Randomly I will take the following example: rgba(122, 143, 186, 0.54) How can I convert this color to the closest Terminal supported color?
5
votes
3answers
397 views

What is the difference having double quotes or not in bash [duplicate]

I have some bash scripts, one which has the following content: #!/bin/bash source $(dirname ${BASH_SOURCE[0]})/script.sh while the other one has the following content: #!/bin/bash source ...
11
votes
3answers
312 views

Variable as command; eval vs bash -c

I was reading a bash script someone made and I noticed that the author doesn't use eval to evaluate a variable as a command The author used bash -c "$1" instead of eval "$1" I assume using eval ...
2
votes
1answer
53 views

how to write `fuser -k -n tcp 80` into a bash script?

Recently, my site's visitor-ship increased sharply. My Apaches' always crash. I'm seeing lines like these in the httpd/error_log: [Sun Apr 13 08:57:18 2014] [warn] child process 7792 still did not ...
5
votes
0answers
82 views
+50

Bash completion for comma-separated values

I would like to create completion rule for comma-separated parameters list. E.g. I have command which receives list of server names: myscript -s name1,name2,name3 At this moment I've managed to ...
0
votes
1answer
13 views

RVM + TMUX—Duplicate entries in $PATH

My Linux terminal config files (.bash_profile, .profile, .bashrc) expand $PATH by prepending some custom directories. This only happens once (and I've also included some ENV vairiable based guards to ...
1
vote
2answers
43 views

About escape with SSH pipe

I want to execute the awk command with long parameters,like this: ssh host "netstat -rn|awk 'NR!=1 && NF>=6 && $1!="Destination" {printf "%-15s %-20s\n", $1, $2}'|sort -f " but ...
5
votes
3answers
45 views

How can I make my .bashrc call to shopt -s autocd depend on the bash version?

In Ubuntu I like having shopt -s autocd in my .bashrc file for automatic CD'ing with typing 'cd', i.e. just type the directory name (and probably use tab completion too) and press return and be ...
4
votes
3answers
188 views

What are the color codes that I can use in my PS1 prompt?

I used several colors in my PS1 prompt such as \033]01;31\] # pink \033]00m\] # white \033]01;36\] # bold green \033]02;36\] # green \033]01;34\] # blue \033]01;33\] # bold yellow Where can I ...
2
votes
2answers
40 views

How can I select a beginning…ending portion of a '/' delimited string (PS1 prompt in my case)

I am customizing my PS1 prompt, specifically the $PWD part which is delimited by /'s among several things I like having the current directory. However if the directory is too long I'd like to have ...
1
vote
4answers
62 views

Alias or Intercept complex bash command with args

How do you create a bash alias for a command with flags? For example, if I run ls -l, I want that to alias to ls -a. This doesn't work: alias "ls -l"="ls -a" Another example: If I type reboot now, ...
1
vote
1answer
60 views

How to check for a folder inside a particular folder in shell script?

I am working on a shell script and python script as well. Python script is passing certain parameters to my shell script and then I am using those parameters in my shell script. Below is my shell ...
1
vote
2answers
218 views

What do the arguments '-v' and '-x' mean to bash?

I have seen a couple of shell scripts with the following shebang: #!/bin/bash -x -v However, man bash does not explain what these arguments -x and -v stand for, if they are belong to bash at all. ...
2
votes
1answer
25 views

redirection failing for CGI program

I'm trying to redirect the contents of command output to a file in a CGI program. The issue for me is that the output file is not getting created. The CGI Code snippet is as follows: #!/bin/bash ...
5
votes
2answers
201 views

Get the actions for a command programmatically

Let's take the git example: $ git<TAB><TAB> git git-import-dscs git-shell git-buildpackage git-import-orig git-upload-archive git-dch git-pbuilder ...
4
votes
2answers
82 views

Opening a file with program in background from shell

The command to launch a program, say evince, from bash shell in background is evince & But what if I want to open some file with evince in background? Nor evince myfile.pdf & neither evince ...
0
votes
2answers
112 views

Yum update problems on CentOS 6.5 minimal as VMware guest

INFO: I am using Windows 7 Pro (64bit) with VMware Workstation version 10.0.1 . I am using CentOS(64bit) 6.5 minimal, for the first time. I am running this from my workplace network, which may use a ...
13
votes
3answers
2k views

Why isn't there any shell command to create files?

Attention please: I am not asking how to make a file from the command line! I have been using touch for making files for years without paying attention that its main purpose is something else. If ...
3
votes
3answers
84 views

Restart a process when I get stderr from another process

I have this constantly running process which POSTs some data collected locally to an endpoint. Now there is some issue in the raspberryPi wifi module and it drops connection frequently. After ...
0
votes
0answers
15 views

Why does SPACE sometimes not work with more (or less)

Usually with |more I press space to get another screenful. But with some commands space just does nothing, and I need to actually keep doing SPACE-ENTER to scroll forward a screen at a time. Both more ...
2
votes
2answers
54 views

PS1 variable no longer shows coloured bash prompt

I'm running a VPS with Centos 6.5 I've setup ~/.bash_profile as in the following screenshot: It used to give me an output like this: Now that I've installed WHM/Cpanel I no longer see coloured ...
0
votes
1answer
19 views

500:Internal Server Error from CGI program

I am trying to write a CGI Program which is invoked from a HTML page . The CGI code snippet is as follows: #!/bin/bash echo "Content-type: text/html" echo "<html>" echo "<body>" ...
2
votes
2answers
44 views

Why is this OSX/BSD/GNU sed workaround not working

So sed behaves differently depending on if it is the OSX/BSD or GNU version. OSX requires sed -i '' <pattern> <file> whereas this works with GNU sed: sed -i <pattern> ...
2
votes
1answer
20 views

calling sigprocmask from bash

I have a process that spawn a bash command with system() while the signal mask has all the signals blocked. This cannot be fixed easily. The bash command eventually execs into a process. The all ...
1
vote
2answers
54 views

copy files from one path to another path in linux

I am new to linux. I am trying to copy files from one path to another path. I have a text file which has all names of files in the following pattern: file-1.txt file-2.pdf file-3.ppt .... I created ...
1
vote
2answers
56 views

Editing a Java properties file with Bash

I have the following Java properties file that is maintained by humans. # file.input = /very/old/name # file.input = /old/name file.input = /current/name file.input.default = /default/name ...
0
votes
0answers
20 views

wget failing when I enter variable name in command

I have a small bash script to download a file from my webserver. I pass the $File variable through the command line and then insert it into the wget command as follows: File=${1} wget -a ...