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

7
votes
2answers
240 views

Is there a shortcut for repeat the second proximate command in bash?

We all know that !! can repeat the last command you do in bash. But sometimes we need to do some operation like $ python test.py $ vim test.py $ python test.py # here is where I need to repeat the ...
0
votes
0answers
11 views

Determin if the currnet terminal has a dark or light theme [duplicate]

I have several (Bash) scripts that uses ASCII color codes. They look good on my dark themed terminal, however on my colleagues light themed terminal the colors I selected don't look that good. Is ...
1
vote
3answers
43 views

How to handle backspace while reading?

How do I handle the backspaces entered, it shows ^? if tried & how read counts the characters, as in 12^?3 already 5 characters were complete(though all of them were not actual input), but after ...
1
vote
1answer
33 views

How could i flip content of a binary file with bash commands

I was wondering if it's possible to do bitwise conversion on a binary file, with bash commands, (in my case bitwise negation).
3
votes
2answers
51 views

Disable bash's cache of executables in the path

On the rare occasions that I notice bash's cache of things that it has found in the path, it's not because it's helpful, it's because it's bloody annoying. An example: ~ dc$ export ...
2
votes
3answers
44 views

bash: dynamic environment control

I have an application which modifies environment variables. The intent is to launch a bash shell with a modified context-specific environment. When my application modifies the environment, and ...
1
vote
1answer
89 views

Reboot when no network connection does not work!

I have a Raspberry Pi that I use as a NAS for my local network. It works fine, but when I turn off the router to which the pi is connected, it permanently loses the connection. To be able to connect ...
1
vote
1answer
71 views

Command-line parameters in bash script not recognised

I use Debian (Raspbian) Wheezy. If this command line works fine: smsd -c sms/out -i 60 -0 -f sms/smsd.log and this alias also works fine: bsmsd='smsd -c sms/out -i 60 -0 -f sms/smsd.log' then ...
4
votes
3answers
48 views

Is it possible to view the list of file names of a zip file which is inside another zip file?

I know I can use unzip -l file.zip to view the file list of a zip file. But a got a zip file inside another zip file. I tried unzip -l file.zip/sub_file.zip, but failed. Is it possible to view the ...
11
votes
3answers
831 views

How to eliminate annoyances when starting a GUI from a terminal?

I prefer to launch GUI applications from a terminal window rather than by using a graphical desktop. A frequent annoyance is that often the developers haven't anticipated this type of use, so the app ...
0
votes
2answers
41 views

How do I validate a settings(ini) file for the values expected using bash?

After I check if the ini file exists where it is expected to be, which I've learned how to do, I would like to check the file for proper formatting. I'd like to validate any number of "site" entries ...
1
vote
2answers
24 views

Remove all files without a keyword in the filename

I have a list of files in the following fashion: > file1.jpg > file1_orig.jpg > file2.jpg > file2_orig.jpg I want to keep all the files with the extension _orig.jpg and discard those ...
4
votes
2answers
34 views

confusing behavior of emacs-style keybindings in bash

Bash offers many useful emacs-style keybindings for simple commandline editing. For example, Ctrl+w deletes ("kills") word left from the cursor. Another keybinding, Alt+d is supposed to be a "mirror" ...
8
votes
3answers
642 views

What is the usage of $& in bash?

I was looking into special parameters in bash. I am curious to know what is $& and how it is different from $_. I see the following output when running the commands but could not locate the ...
4
votes
1answer
113 views

Backspace deletes Bash prompt

I recently modified my Bash prompt via the $PS1 variable so that I could have color. It is in my .bashrc file: PS1="\\[\e[0;32m[\h::\W] >>\e[m " Now if I type something and then have to ...
3
votes
0answers
9 views

syntax highlighting in bash (in terminal) [duplicate]

Is there a way to make bash shell in a terminal use syntax highlighting? There are few related questions on Stack exchange, but with no clear conclusion. What I am looking for is to have bash ...
3
votes
3answers
222 views

Preventing a specific space from being expanded in a variable

In bash how do you avoid a specific space from being expanded in a variable? Lets say I have this JAVA_OPTS="-Xmx1g" JAVA_OPTS="$JAVA_OPTS -XX:OnError='/path/to/a/script.sh %p'" function args() { ...
0
votes
1answer
61 views

Running Python script over multiple directories and multiple files

Here is my command line for python: python script.py -a .faa -n .fna I have a directory containing multiple directories. Out of these multiple directories, there could be 1 or more folders. In ...
1
vote
1answer
35 views

Calling `source` from bash function

I'm trying to source a file whose name is passed from stdin. My plan is to create a function like this: mySource() { # get stdin and pass it as an argument to `source` source $(cat) } to be ...
0
votes
1answer
51 views

Using bash's “source” command return error though it successfully read config file [duplicate]

I want my bash script to read parameters from config file. Here is what inside the script: #!/bin/bash source /home/myscript/conf/config.conf echo "$username" and below is my config.conf: ...
3
votes
3answers
90 views

Script to email all matching files in a directory

Trying to set up a bash script to automate sending data files. Desired end result is to check a specified directory once per week, make a list of all Excel files modified within the last 2 days, and ...
2
votes
2answers
55 views

Why does the while cycle skips and only reads the first line?

$ ls testscript.sh testservers.txt $ cat testservers.txt serverA IMM 10.2.3.4 USERID PASSW0RD serverB IMM 10.2.3.5 USERID PASSW0RD $ $ $ cat testscript.sh #!/bin/bash # test them.. egrep ...
1
vote
1answer
153 views

Why are these values not appending correctly when appended to the pipeline? [duplicate]

I have a bash script (seen here) that I'm using to sort a list of files in subdirectories by filename. This script appends sorted files in hooks/pre-relevant/, then files named hooks/pre-relevant, ...
0
votes
1answer
28 views

typeset -A is giving error in script

I was using associative arrays in my script, hence I used to declare them by the typeset -A <array_name> command, and it worked fine in the bash prompt But when I use it in my script, I get ...
1
vote
1answer
71 views

Permission denied when trying to run script as other user

I'm trying to run a script as another user that starts a piece of software (Etherpad), which is run like so (from root): su -c "/var/www/etherpad-lite/bin/run.sh" -s /bin/bash etherpad but I'm ...
5
votes
4answers
367 views

How do I prevent less from clearing the screen on exit? [duplicate]

I often pipe commands to less in order to read through the output (e.g. compiler errors). MyCommand | less This is great because it makes trawling through large amounts of output easy, but when I ...
3
votes
2answers
77 views

Getting the combined count of all occurences of a string under multiple directories?

I have a (hopefully) interesting problem that I could use some advice on. I have a system that's essentially used for storing logs. It has a directory structure like: YYYY/MM/DD/hostname/ There are ...
0
votes
1answer
102 views

How to copy two files in expect script?

please advice why spawn scp $FILE1 $FILE2 $LOGIN@$IP:/tmp in my expect script copy only FILE1 and not copy FILE2 ? I try to to transfer both files by scp as scp file1.csv file2.crt ...
5
votes
2answers
63 views

exclude particular file from bash_completion

I have a simple bash_completion code. The only thing it does, is when I type grcat and then Tab, it offers to complete filenames from /etc/grcat. _grcat() { local word COMPREPLY=() if [ 1 ...
1
vote
0answers
41 views

When gnu parallel exit,my program also fail

I use gnu parallel to run a bash function. The function just contains the bash script to restart my program. At first, the restart is ok, but when the gnu parallel script exits, my program also fails. ...
3
votes
2answers
50 views

Why is my trap not printing any log message?

What I'm doing is, trap 'rm -f /path/of/file/fileName.running; echo "TRAPPED & READY";' 1 2 9 15 >> trap.log I didn't get anything in log & the file which should have been deleted ...
15
votes
5answers
1k views

Parenthesis in bash arithmetic: 3 * (2 + 1)

expr does not seem to like parenthesis (used in mathematics to explicit operator priority): expr 3 * (2 + 1) bash: syntax error near unexpected token `(' How to express operator priority in bash?
0
votes
1answer
78 views

What is the exact function of this malicious bash one-liner?

I can't figure out what this is trying to do. The part between backticks looks like a plain old forkbomb, but the base64 doesn't seem to decode to anything sensible. Can you help? Don't run it, ...
0
votes
4answers
53 views

How do I call an executable as if it were called from another folder?

Let's say I have a program food in /bin/ that creates the file dinner.txt like so: #!/bin/bash touch dinner.txt I want to use my food program to create dinner.txt in my /home/ folder without ...
11
votes
1answer
378 views

How do command-line tools have their own autocomplete list?

How does Bash in Ubuntu know a tool's specific list of actions? For example if I type apt-get and tab twice I only see remove, update, upgrade ...etc, but not the actions for another command or the ...
4
votes
4answers
82 views

Bash history in script: `!#:*`

I have been reading through the study guides for the LPIC-1. echo "This is a sentence. " !#:* !#:1->text3 I'm having trouble understanding how the above line of code repeats the echo command ...
1
vote
1answer
46 views

How do I add an associative array to a variable from an external ini file?

I'm modifying a simple script to add function and learn more about how to write bash scripts. Currently, the script creates associative arrays using a function: declare -A site theme add_site() { ...
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
28 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
49 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
467 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
101 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
35 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
29 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
89 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
54 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 ...