Questions specific to GNU’s Bourne Again SHell, as opposed to other Bourne/POSIX shells. For questions about Unix shells in general, use the /shell tag instead.

learn more… | top users | synonyms

13
votes
4answers
14k views

How can I force unzip / zip not to create a subdirectory when I extract it?

Depending on how a zip file is created, sometimes it will extract all of the files directly, and sometimes it will extract the files into a subdirectory. If the latter is true, how can I force the ...
1
vote
1answer
27 views

Event dispatcher in bash (Ubuntu Gnu/Linux) [duplicate]

Are there any methods or bash tools that can observe some events (such as creating a folder) and then do another actions?
4
votes
4answers
34k 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 ...
3
votes
1answer
25 views

Loop over a string in zsh and Bash

I would like to convert this Bash loop: x="one two three" for i in ${x} do echo ${i} done in such a way to work with both Bash and zsh This solution works: x=( one two three ) for i in ${x[...
6
votes
1answer
60 views

Displaying usage comments in functions intended to be used interactively

I have a number of functions defined in my .bashrc, intented to be used interactively in a terminal. I generally preceded them with a comment describing its intended usage: # Usage: foo [bar] # Foo'...
0
votes
1answer
35 views

Why does my terminal say I'm running -bash (with a leading dash) and not bash?

I have recently started learning UNIX for a week or so and I've played around with the bash_profile and bashrc files to add in some basic preferences. But today, I couldn't execute several terminal ...
6
votes
2answers
84 views

Read special keys in bash

I am playing with a script that, among other things, list a selection-list. As in:1) Item 1 # (highlighted) 2) Item 2 3) Item 3 # (selected) 4) Item 4 When user press down-...
3
votes
2answers
77 views

Comparing Negative values in bash using arrays

I do have a interesting problem that I am trying to tackle but I am yet unable to do so. Let suppose that I have 2 arrays. Array One: 1 -2 3 -2 2 -4 Array Two: -2 -3 4 5 2 -5 I want to be able ...
1
vote
1answer
127 views

“-bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)”

Running a brand new Ubuntu 16.04 and a Debian 8 server. Trying to connect via ssh and getting the following strange terminal output. I refer to the rectangles with the numbers in it. The problem ...
-1
votes
1answer
34 views

cancel script execution and continue [closed]

I have a script which runs another script. myscript.sh #!/bin/bash .... cd /folder/ sh run.sh sh another_script ... the procedure: So , I start running myscript.sh , the script runs it's ...
1
vote
1answer
30 views

Autocomplete deletes last character from words sometimes

I have a custom command define that gets words definition from dictionary. I wanted to make an autocomplete script to complete the words I want to define using the list of words found in /usr/share/...
0
votes
2answers
44 views

aliasing command which takes argument with using pipe

I would like to create an alias in my ~/.bash_profile that will: Take two arguments $1 $2 Pass these to diff Pipe the output to less I have not found any solutions on Stack that do what I need, ...
3
votes
1answer
39 views

how to set globstar for noninteractive shells

I would like to execute commands noninteractively on a remote server that use the ** globstar option. However, globstar is not set by default on the remote, and bash doesn't source any files in ...
2
votes
2answers
35 views

Mouse click integration with SSH client, on command line, not just vim?

In vim, you can use the option :set mouse=a, and then (if your SSH client supports it) you will be able to simply click and the cursor will move, rather than having to use the arrow keys or whatnot. ...
-2
votes
3answers
56 views

Simple way to make test file in bash

Working with file reading instruments I regularly need some text file to test a code. I would like to make such file quickly. I guess it would be great to produce the file with some bash one-liner. ...
5
votes
1answer
75 views

how to make a non-privileged script drop even the privileges it has on a file

Is it possible from a bash running as a non-privileged user to mark the file immune so it cannot be altered in any way from any process running as that user? It is OK if other users or a root can ...
1
vote
2answers
61 views

Executing commands consequtively on multiple folders

I have parent folder "parent". Inside this folder I have subfolders, and a file named "names.txt". this file includes the names of these subfolders as follow: Parent_folder folder1 folder2 folder3 ...
0
votes
0answers
23 views

How to selectively disable auto-complete?

I've created a large number of utility scripts, that I use to make my work-life easier. All of those reside in my home directory, so that I can easily run them as ~/<script>. Being as clumsy as ...
1
vote
2answers
59 views

chown doesn't work through script

I have a script: #! /bin/bash sudo chown -R $USER:$USER /opt/Folder The chown doesn't seem to execute. If I just write the above line from terminal ,it runs fine though! I have read this but ...
0
votes
2answers
24 views

Bash scripting: Change standard error message for custom one

I have been trying to work on my own little backup script. I am running into an issue when I run my script and the rm command has nothing to do. I would still like to process the output (aka display ...
4
votes
3answers
3k views

Using chown $USER:$USER inside bash script

In a small bash script I'm running I am attempting to chown a new directory that is created. I've added: sudo chown $USER:$USER /var/www/$sitename sudo chmod 775 /var/www/$sitename after the line ...
0
votes
2answers
2k views

How to redirect output of a 'xterm -hold -e' command

I know you can use tee to log output from a command in a terminal, e.g.: df -h | tee ~/log.txt However, how can I do this with a more complex command like this: xterm -hold -e program arg1 arg2 ...
3
votes
3answers
2k views

Show only current and parent directory in bash prompt

I'm new to bash and would like my prompt to show something that in tcsh was trivial, yet after a good google search I still cannot do. I would like my prompt to include only the current and parent ...
0
votes
1answer
16 views

exiv2 piped to grep - random inconsistent behavior

For a bunch of jpg photos, I have this (simplified) script to be able to extract the original date when the photo was taken (if different of 0000:00:00, not relevant for this case) for f in *.jpg; do ...
23
votes
1answer
845 views

What is the bash '<(file contents)' syntax called?

This answer on Security StackExchange uses an interesting bash syntax to generate a file in-line: openssl req -new -x509 -nodes -newkey ec:<(openssl ecparam -name secp384r1) -keyout cert.key -out ...
14
votes
9answers
6k views

How to remove multiple newlines at EOF?

I have files that end in one or more newlines and should end in only one newline. How can I do that with Bash/Unix/GNU tools? Example bad file: 1\n \n 2\n \n \n 3\n \n \n \n Example corrected file:...
1
vote
2answers
34 views

How to start a new shell, pass it new environment variables, and work there until exit?

I need a special shell environment set up to interact with an commercial application that we have purchased. The environment is queried "on the fly" from the application. So I've attempted to start ...
112
votes
3answers
67k views

How to cycle through reverse-i-search in BASH?

In the terminal, I can type CTRL-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 ...
0
votes
2answers
33 views

Remove string that has special characters

I have a file called test similar to the following: hello my name <h6>test morning</h6> is bob I know I would use: sed -i -- 's/name//g' test To remove name from the file, but how do ...
0
votes
1answer
46 views

Non-Interactive input

I am trying to run a bash script which downloads and runs another script. The second script contains questions that must be answered by input. I have already attempted to use expect but it fails ...
1
vote
0answers
25 views

Make Bash's vi-mode default to “normal” Vi mode (not “insert”), and place cursor at start of line, mimicking KornShell

I'm trying to get Bash to mimic the behaviour of KornShell93 (ksh) when the shells are in Vi command line editing mode. KornShell defaults to "Vi normal mode" (a.k.a. "command" mode) and it also ...
2
votes
3answers
4k views

How to remove element from the list?

I have written a command that output a list of hostnames, e.g. : clab148node11 clab148node12 clab148node15 clab148node16 Now, I would like to remove those nodes that do not respond to ping. For ...
0
votes
2answers
231 views

Why does this compound command report errors when copying directories?

If one executes the following two commands in one line as follows, rm -rf dir ; cp -r dir2 dir it may return that cp can not create directory dir/subdir: File exists but if these two commands are ...
-3
votes
1answer
37 views

Check the frequncy of a character's consecutive occurences [closed]

I need a way (in Bash) to check the consecutive occurrences of a character, however it also needs to be capable of having a limit of occurrences before it is considered to be a second variable, in ...
12
votes
1answer
236 views

See the expansion of Bash variables for debugging?

Is there any tools/tricks available for expanding variables to make bash code easier to read? For example it would convert the following: DIR=/var/tmp FILE=${DIR}/file SCRIPT_ROOT=/opt/root TOOL=${...
4
votes
4answers
421 views

How to obtain grep exit status into a variable

I started learning Bash a couple of days ago. I'm trying to obtain an exit status of grep expression into a variable like this: check=grep -ci 'text' file.sh and the output that I got is No ...
0
votes
1answer
20 views

How to use bash variables inside make

I thought that make interprets the rule's set of commands literally, passing them to the sub-shell. But this doesn't seem to work in this case: default: loop echo $$RANDOM This prints echo ...
2
votes
2answers
32 views

How to specify protocol prefix containing “:” to bash-completion function _known_hosts_real

I am attempting to use bash-completion for URLs of the form "proto://host". Without the ":", I see expected behavior, with the ":" present, the URL comes out "faulty". Bash completion has a function ...
1
vote
1answer
38 views

Pipe demon output to a function

I'm receiving a MQTT message with mosquitto_sub and I want to redirect the output (two strings) to a function. CLIENT: mosquitto_pub -d -t hello/world/ -m "Alessio,base64" On the server I have a ...
2
votes
2answers
67 views

bash:Syntax near unexpected error '(' [closed]

I am following a tutorial in computational microbiology: William Lindstrom, Garrett M. Morris, Christoph Weber, and Ruth Huey (2008-01-29). Using AutoDock 4 for Virtual Screening. Scripps Research ...
1
vote
3answers
71 views

Read lines from a file into a variable

I'm trying to automate a large process to save time and effort and I'm probably making it way harder than it needs to be. What I'm doing so far is: #!/bin/bash LISTFILE="/tmp/filename" for FILE in $...
28
votes
3answers
4k views

Bash - How can I make “Press any key to continue”

I'm making a script to install my theme, after it finished installing it will appear the changelog and there will be "Press any key to continue" so that after users read the changelog then press any ...
35
votes
5answers
11k views

How can I `alias sudo !!`?

I'm trying to set an alias for sudo !! in Bash. I tried alias sbb='sudo !!', but it interprets that as a literal !! and prints sudo: !!: command not found If I use double quotes, it substitutes ...
0
votes
1answer
70 views

Writing output of command to variable [on hold]

I would like to put the output of a command into a variable. As far as I know, you have to use either of these: variable=$(command) variable=`command` The following should work from my point of ...
0
votes
1answer
22 views

Bash - How can I make selection menu of zip files based on how many zip files in a directory?

I am doing a theming tool script. I want to make a selection menu of zip files (zip file contain theme) in a directory, then users will choose a zip file they want to install Example: in /theme/...
1
vote
1answer
36 views

Colour-coordinate symlinks/softlinks based on where they refer to

Is there any way to colour coordinate symlinks/softlinks based on where they're linked, or maybe by who they 'belong' to (similarly to colouring the output of ls for example)? To give you an example ...
6
votes
5answers
9k views

Constantly check if file is modified bash

I have a file called file1 I want in a script, whenever there is a change in it, do something, a beep sound actually. How do I do that ¿? Thank you in advance
1
vote
0answers
31 views

evaluating dual blocking commands in a bash condition statement

I am attempting to write a loop that refreshes a terminal either 1. when the file(s) have been modified, or 2. When user input is detected second interval. I know how to do one at a time, like so: ...
88
votes
3answers
3k views

Security implications of forgetting to quote a variable in bash/POSIX shells

If you've been following unix.stackexchange.com for a while, you should hopefully know by now that leaving a variable unquoted in list context (as in echo $var) in Bourne/POSIX shells (zsh being the ...
2
votes
0answers
52 views

Bash completion extra space when adding file directory

I have a script for extending bash-completion for certain commands. If I type command1 and do a tab, it should auto-complete with a file directory (and the files). It works fine expect for one ...