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

7
votes
6answers
610 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
454 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
3answers
47 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. I also want to be able to store the error messages ...
4
votes
2answers
114 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
36 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
72 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
103 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
57 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
12 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
403 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
325 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
57 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
116 views

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
17 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
44 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
46 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
195 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
42 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
66 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
219 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
28 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
205 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
96 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
185 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
89 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
16 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
57 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
20 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
45 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
58 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
63 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
21 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 ...
2
votes
1answer
53 views

Specifying full range of printable ASCII characters in a glob pattern

I want to use a globbing pattern to match only printable (including space) ASCII characters 0x20 through to 0x7e. This is being used inside a super super.tab database. I've arrived at the pattern: ...
2
votes
2answers
82 views

Close all file descriptors in bash

Is there a way to close all the open file descriptors, without having an explicit list of them beforehand?
0
votes
2answers
35 views

command condition sometimes integer sometimes string

I want to execute this condition while [ $(cat /path_of a file/) -eq 1 ] The condition is only correct if $(cat /path_of a file/) is an integer and not a string ! How can I overcome this ...
1
vote
0answers
42 views

how to edit and color bash's tab completion list

Following is what i would like to have. When the tab completion is ambiguous, and bash prints the list of possibilities. I would like it to colour the next character I should press inside every word ...
1
vote
1answer
64 views

Add arguments when completing a command name

I am looking for a way to expand some predefined strings in the terminal when tab (or another key combination) is pressed. This is different from tab completion. My terminal already expands ~ to my ...
2
votes
2answers
62 views

bashrc that calls other bashrc depending on linux distro

I login to a system that reads my bashrc file and loads some software ready to use. I'd like to load a given bashrc file depending on the linux system that I am logging into. Specifically, if I am ...
3
votes
2answers
83 views

Passing arguments to su-provided shell

man su says: You can use the -- argument to separate su options from the arguments supplied to the shell. man bash says: -- A -- signals the end of options and disables further option ...
1
vote
2answers
47 views

Bash: split list of files into different files?

I have several files in a directory like: data1.dat data2.dat .... data24678.dat To run another code, I need to have a text file with the names of the files but I need to split in 50 files per ...
2
votes
6answers
164 views

How to keep Bash running after command execution?

I would like to run something like this: bash -c "some_program with its arguments" but to have an interactive bash keep running after some_program ends. I'm sure -c is not a good way as man bash ...
2
votes
1answer
53 views

Difference between “eval” and “source /dev/stdin”

What is the difference between eval and source /dev/stdin? For example, we can run a list of commands in various ways like this. with eval. comd="ls" eval "$comd" with source /dev/stdin printf ...
1
vote
0answers
32 views

Transparent encryption of bash history?

I'm not sure if anyone has done such things before. I want bash history to be fully encrypted, prompt for password when in interactive session. Is that possible?
1
vote
2answers
10 views

Install-on-Demand Wrapper Function for Executables

How do I make the following function work correctly # Install git on demand function git() { if ! type git &> /dev/null; then sudo $APT install git; fi git $*; } by making git $* ...
5
votes
3answers
157 views

Apache server starts automatically after stopping the service

What can cause httpd to start automatically after stopping it? In a bash script I need to first stop apache web server. This is the script: apachectl stop; while pgrep httpd; do sleep 1; done echo ...
3
votes
3answers
105 views

Bash script error: integer expression expected

I'm having a rather weird issue, I'm running a script (Bash) on multiple servers and it stopped working on one of the servers (works perfectly fine on all other servers). Here is the problem part of ...
0
votes
4answers
51 views

Mass mv on files and changing filenames [duplicate]

I want to change these filenames download (19).download ... download (27).download to download (19).html ... download (27).html I run unsuccessfully mv *.download *.html usage: mv [-f | -i | ...