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

2
votes
1answer
43 views

How to use " rm !(*keyword) in bash 4.1.2?

I got bash 4.1.2 on remote centos machine. When using my favorite rm !(*keyword) I got bash: !: event not found I tried to upgrade its bash, but seems the edition remains after upgrade. The ...
1
vote
1answer
27 views

Replacing shell variable names in another variable

I've been wrestling with bash variable substitution for a while now and can't figure this out... I have a variable with a command template: CMD_TMPL='sudo -u ${USER_NAME} ${USER_HOME}/script.sh' ...
1
vote
1answer
45 views

Bash Autocompletion (rather than tab completion)

How can I make bash show completion suggestions without having to press [tab]. I'd like the suggestions to update on each character I add and maybe to have the ability to quickly pick an option. I'd ...
0
votes
0answers
24 views

How to make the process run after closing the session [duplicate]

I have started a process in Linux without a terminal multiplexer like screen or tmux, without nohup. Now I want to logout from my remote ssh session without interrupting the execution of that process. ...
2
votes
1answer
464 views

Why is 'kill -9' killing browser as well as server?

I sometimes have to use kill -9 as a last resort to kill my rails server. Unfortunately, I have to do that often enough that I wrote a helper function in my bash_profile to do it. If I do it manually ...
2
votes
2answers
85 views

How to check whether a particular port is open on a machine from a shell script and perform action based on that?

I am running my below shell script on a machine on which c++ application server is running on port 8080 and in the shell script I am executing an URL and stores the response coming from that URL in ...
0
votes
1answer
30 views

What does meta+n do in the terminal

When I click this it replaces whatever I have currently typed into the buffer with a :. Hitting backspace will go back to whatever I had in the buffer but I can't seem to find what the hell it's ...
0
votes
1answer
32 views

Download yad with bash script

i'm building a simple deb package (single binary) for a little project i've been working on. Now I want to build a nice interface around it and used zenity for a couple of times, but this time I ...
8
votes
4answers
1k views

Why is the 'if [ $1=“1” ]' branch always selected even if $1 is not 1?

I have a shell script named 'teleport.sh' like this: if [ $1="1" ]; then shift mv "$@" ~/lab/Sun elif [ $1="2" ]; then shift mv "$@" ~/lab/Moon elif [ $1="3" ]; ...
1
vote
1answer
27 views

Modify $READLINE_LINE and $READLINE_POINT values inside bash script

I already asked this question on stackoveflow, but received no answer and very few views. I thought I would post here as there should be more bash users and someone might have already stumbled upon ...
1
vote
4answers
84 views

Bash: Convert Multi-line output to Single line

I am getting a multi-line output as follows: Actual Output: GenuineIntel,Intel(R) Xeon(R) CPU E5-2687W 0 @ 3.10GHz,CPU0,64,EM64T Family 6 Model 45 Stepping 7,(null),3093,0 GenuineIntel,Intel(R) ...
22
votes
2answers
1k views

what does the dash `-` before `bash` on 'command not found' errors mean?

When you enter an invalid command at a bash prompt you get the message -bash: {command}: command not found What does the - at the very beginning signify?
0
votes
2answers
53 views

Shell script to work on files in some directory

I am a noob in Linux hence this might come as a silly question. I have a Windows system, so I downloaded cygwin to help me execute Linux/unix commands. I need to execute a shell script on a bunch of ...
0
votes
0answers
17 views

goaccess won't run when called from CGI script

I'm trying to make a CGI script (for nginx) that outputs an html page containing the usage statistics for my server. I'm using goaccess 0.7.1 and CentOS 5 x86. I've configured nginx to run my bash ...
0
votes
2answers
37 views

Getting expr: syntax error on index [duplicate]

Using this OF=$(ps fax | grep 'php-fpm: master process' | awk '{print $1}') IDX=`expr index $OF ' '` I get an error. The results of the $OF variable are: 27797 27495 What is the error here? I ...
0
votes
1answer
63 views

Reject SSH connections from unlisted countries, using hosts.allow/hosts.deny on CentOS

I was trying for few hours to make my custom script work when using hosts.allow/hosts.deny, to prevent connections to SSH and other services supporting TCP wrappers from unlisted countries. Example ...
1
vote
0answers
23 views

How to make netcat print colourful text?

on my Mac I have an peripheral that sends text data to localhost:2332. Some of them are coloured, like this: "\e[1;31mRed text here\e[m normal text here", I use nc loacal host to monitor the data ...
2
votes
5answers
40 views

Append files with bash one-liner?

Currently I use multiple lines to append content into a combined file, e.g. ./myprogram 1.txt > Out.txt # Overwrite for the 1st file ./myprogram 2.txt >> Out.txt ./myprogram 3.txt >> ...
1
vote
1answer
35 views

Expand shell variable without globbing

I want to check whether an input string refers to a file name - not a wildcard string like *.txt. This doesn't work: if [ -f "$1" ]; Because $1 gets expanded to *.txt, which gets expanded to, say ...
1
vote
2answers
40 views

Sending most recently created file via Email

I'm trying to send a log file every 24 hours or so via email. Currently I am using mutt for this. You can call mutt like this: mutt -s "Log" -a file_attachment example@example.com I know I can ...
-3
votes
1answer
39 views

to run script over several folders? [duplicate]

Currently I have a script that can run only in a single folder. #!/bin/bash for file in ls -1 *.jpg|sort -t . -n -k 3 do echo "compute ./scripName $file" ./scriptName $file done Question: I ...
1
vote
1answer
58 views

Replace a string in a file and overwrite the file

I wrote my script using the the directory ~/deleted (it's a long script). after using ~/deleted for the whole script. I want to let the user choose the directory by putting the path in ~/.rm.cfg. My ...
8
votes
0answers
269 views

scroll through output using `less` or `tail -f` while keeping the header visible [duplicate]

I am trying to scroll through some data formatted thus- NFI T[PSEC] T[K] EKIN(PSI) E(RHO) ECONS ANNEE ANNER !> 1 0.00012 0 0.45873 16.26904 16.72777 ...
1
vote
2answers
51 views

How do I suppress a warning message?

touch ~/deleted/$(echo "directory_"$(readlink -f foo)|tr '/' '\') 2> /dev/null where foo is a directory It's reading the full pathname of foo and creating it as a file replacing all '/' with '\' ...
0
votes
2answers
39 views

Determining the exit status of the “return” built-in

I was reading about traps, but only return works for me in my shell script, so was wondering what status or code it returns, so what I tried is, #!/bin/bash seeOutput=`return` echo $seeOutput It's ...
1
vote
1answer
19 views

'script' session logging makes me exit twice

I'm using a solution described here to log my shell sessions, by adding this to the end of /etc/bash.bashrc: test "$(ps -ocommand= -p $PPID | awk '{print $1}')" == 'script' || (script -f ...
0
votes
0answers
21 views

Can't access GPIOs when switching to systemd, but why?

I'm using this ARM AT91 Sam9x5ek Embedded Device, with my Linux Images made by a Buildroot. Usually my init-system is Busybox, now I changed it to systemd. Since then I can't access the GPIO anymore, ...
1
vote
3answers
73 views

Network statistics on linux

I am trying to write a small script to gather network statistics on my Linux system. Is there any way I can do this? What I'm after is live stats on current network throughput. I have done some ...
0
votes
1answer
21 views

Alternative for jq in debian wheezy to parse json in bash

In Ubuntu you can simply install jq apt-get install jq but on debian it is not in the repository. Is there an alternative commandline to parse a JSON string on the console? maybe you can achieve ...
3
votes
1answer
31 views

Problem with regular expression in gawk ('\<' not working)

I am trying to get into bash a little bit. I was going through this guide but the second example in this subsection on gawk doesn't seem to work. The problem is this command: ls -l | awk ...
2
votes
3answers
77 views

Run a script on multiple shells?

I have two servers one AIX with default shell ksh, the other RHEL with default shell bash. I have a script that is mounted on both that will run similar commands but for either AIX or Linux. This ...
1
vote
1answer
36 views

Compare file size of multiple files in an array [closed]

Scenario: Ftp site has 100s of files. Once a day, all the .gz files are copied to an AWS site then renamed. Only the date is kept in the file name. Some of the files corrupted during copy. A txt ...
2
votes
2answers
67 views

Is a ? treated in a special way in parameter expansion?

I'm attempting to parse to output from git status --porcelain -b for use in my prompt but I'm coming across strange behaviour when performing parameter expansion. This snippet should demonstrate the ...
0
votes
2answers
64 views

Nested loops, if conditions, and background jobs in bash

I have a bash extraction function that I am trying to parallelize. Its job is to find and extract nested archives. Ideally, I want the if evaluation and all of its actions to be sent to the ...
6
votes
1answer
73 views

How to customize Bash command completion?

In bash, it's easy enough to set up customized completion of command arguments using the complete built-in. For example, if, for a hypothetical command with a synopsis of foo --a | --b | --c, you ...
1
vote
3answers
85 views

How to disable a shell keyword?

Using enable builtin command we can disable a shell builtin command, for example echo, as follow: enable -n echo But how can we disable a shell keyword like time? If we try: enable -n time we ...
1
vote
2answers
36 views

Remove unneeded file lock in script

I have some script using flock executable. It works well. Problem is when this script calls another script, and it creates background process. In this situation background process inherits file locked ...
2
votes
2answers
247 views

condition && command + exit

While writing a simple shell tool, I found a piece where I don't know how to get it to work. [ "$#" -ne 3 ] || echo "wrong number of arguments" && exit The above works as intended because ...
4
votes
4answers
439 views

Place job in background without freeze

Say you start the job like this foo and then desire that you want to place it in background. Typing Ctrl+Z and then bg does the trick but will freeze foo between Ctrl+Z and bg. How can I place foo ...
2
votes
0answers
26 views

Tmux log output [duplicate]

Im looking for a solution to an issue regarding tmux. One of my scripts ns2server stopped working recently when running start (using tmux) but not in debug mode (not using tmux). I found that using ...
2
votes
1answer
47 views

How does bash actually change stdin/stdout/stderr when using redirection/piping

Unfortunately I've had no luck figuring this out, as everything I find is just on the syntax of redirection, or shallow information about how redirection works. What I want to know is how bash ...
3
votes
4answers
257 views

Make many subdirectories at once

Suppose I have a directory /, and it contains many directories /mydir, /hisdir, /herdir, and each of those need to have a similar structure. For each directory in /, there needs to be a directory doc ...
0
votes
3answers
72 views

Whats wrong with this code? [closed]

#!bin/bash if [ ! -e $1 ]; then echo "error... no such file" exit else END=$(wc -l $1 | cut -d" " -f1) for (( i=1;i<=END;i++)); do echo -e " $i \n" ...
2
votes
2answers
104 views

Bash copy all files that don't match the given extensions

When I import pictures from my camera in Shotwell, it also imports the video clips. This is somewhat annoying, as I would like to store my videos in another folder. I've tried to write a bash command ...
4
votes
1answer
56 views

Is it possible to use multiple here-docs in bash?

Can one use multiple here-docs to provide input to a command in bash? $ cat <<<foo <<<bar bar $ cat <<EOF1 <<EOF2 > foo > EOF1 > bar > EOF2 bar Obviously, ...
3
votes
2answers
83 views

bash - complex prompt

I want to have really complex prompt. It should contains login, computer name, date, time, working directory, result of last command and new line symbol. I want to color each item as well. So I ...
2
votes
3answers
49 views

Shifting command output to the right

Say I'm writing a .bashrc file to give me some useful information in my login terminals and I'm telling it to run the cal command (a nice one). How would I go about shifting the calendar produced to ...
6
votes
3answers
154 views

Attempted assignment to non-variable?

We can use arithmetic operations inside shell script function: function mess { if (( "$1" > 0 )) ; then total=$1 else total=100 fi tail -$total /var/adm/messages | more } I ...
15
votes
2answers
372 views

Is dash or some other shell “faster” than bash?

I always thought that the only benefit of using dash instead of bash was that dash was smaller, and therefore many instances of dash would start faster at boot time. But I have done some research, ...
1
vote
2answers
37 views

Call background process back to stdout

Is it possible to "call" a background process output to be shown in the terminal? Example: cron starts apt-get to update the system and I want to see the output of apt-get