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

3
votes
2answers
17 views

How can I move files into subdirectories by count?

I have around 100,000 files in a directory. As you can imagine, that's not an ideal situation, and I'd like to split the directory up into subdirectories. But the filenames aren't such where I can put ...
-2
votes
3answers
47 views

I know echo is a built-in bash command, but have some binaries in the /bin/ folder why? [duplicate]

In all my life i think the "echo" is a built-in bash command, if you look at man bash, you will think that too. But looking at my computer which echo /bin/echo I discovered echo have a binary. ...
2
votes
0answers
23 views

cd with double slash hangs forever on Mac OS X Terminal

If I type cd // on the Mac OS X Terminal (Version 2.6.1 (361.1)), the prompt hangs forever. Why? Curiously that doesn't happen if I do cd / or cd ///. I am using El Captain with the bash that comes ...
1
vote
1answer
9 views

Bash completion extra words Fedora 23

I am new to using Linux. :) Today I noticed some extra words when TAB completing dnf search. I am not sure how to google this (I tried, but with no success), so please help. :D Anyone has any idea ...
1
vote
2answers
58 views

forward aliases to child process

I have some aliases which are defined in /etc/zprofile (or /etc/profile for bash). Also $PATH gets manipulated there. I want to start an interactive shell from a shell which avoids the $PATH ...
11
votes
1answer
268 views

exec and tee to the logfile: explain these bash commands

I saw this at the top of my bash script file: export LOGFILE=$LOGDIRECTORY/${SCRIPT_NAME}.log exec > >(tee $LOGFILE) exec 2>&1 What does it do? What are two exec processes doing here? ...
0
votes
1answer
25 views

Send array to subshell function with pipe?

I really need to get an array to a subshell so the processes can run together in one script. I know I cannot export an array but is it possible to send it through a pipe to a subshell, and how would I ...
8
votes
4answers
6k views

Hybrid code in shell scripts. Sharing variables

This answer discusses how to run a multi-line Python snippet from the command line in a terminal. I noticed that the answer works great within shell scripts, even with nested indentation, which is ...
90
votes
3answers
54k views

Why does my shell script choke on whitespace or other special characters?

Or, an introductory guide to robust filename handling and other string passing in shell scripts. I wrote a shell script which works well most of the time. But it chokes on some inputs (e.g. on some ...
1
vote
2answers
31 views

Bash script to count file types in a path (including subfolders)

I would like to get a quick overview over the different file types in a directory (including all its subdirectories) using the file tool, e.g. telling me what file type is the most common one there. ...
1
vote
2answers
390 views

How to execute “Yes/No” operation as long as I press “Yes” in bash?

Suppose I have the Yes/No construction in bash script: read -r -p "Yes or no?" response if [[ $response =~ ^([yY][eE][sS]|[yY])$ ]] then do ... else exit 0 fi I want this construction to be ...
1
vote
2answers
21 views

replace the content of one field based on the content in another field

I would like to divide the first column based on the delimiter, here -. Based on the last value, last column, here column 2, should be populated. If the value is 01 or 99 then replace with 2 or 1 ...
0
votes
1answer
20 views

In tmux how do I create a new pane with the right pwd while running a command in the parent pane?

If I create a new pane B from pane A and I'm not running any commands in A then B gets created with the same pwd as A which is what I want. However if while creating the new pane I'm running a bash ...
5
votes
2answers
1k views

Can I set a bash timeout only for virtual consoles (ctrl+alt+{f1-f6})

I know that I can set a TMOUT variable to automatically end a bash session after a specified period of inactivity. However, what I want is to apply that only to my 6 built-in virtual consoles, which ...
0
votes
0answers
34 views

Array value won't get printed out

I have the below bash script, but rather that I get the command executed stored in cmd[1] it prints [1]: command not found. I executed the command with the following way: $ qsub -J 1-33 sicer-pbs.sh ...
0
votes
0answers
30 views

Send command to open process in Shell file

In bash how can I issue a command to a running process I just started? For example; # Start Bluez gatttool then Connect to bluetooth device gatttool -b $MAC -I connect # send 'connect' to the ...
0
votes
1answer
25 views

How to compare current date and date from line in txt file?

I want to check when week left before the certificate expires for our users on Openvpn server. On server installed Centos 6.7. I can export enddate and subject from all .crt to txt file with the ...
0
votes
2answers
59 views

How to process a file containing quotes?

I know a fair bit about escape characters in BASH. I know that \ will escape the next character, " " will escape all characters except for $ and ", and finally ' ' will escape all characters except ...
-1
votes
2answers
73 views

Have sed echo string after match

I need to have the string directly following/pbs.twimg.com\/profile_images\/echoed out. This is for a search tool I have created with a bit of help, and everyone recommends sed, but I never really use ...
3
votes
4answers
44 views

Does \ work for escaping functions?

I have a function defined in my .bashrc that I would like to bypass: function func() { // func } export -f func When I run env -i func I can access the func command without the function in the ...
1
vote
1answer
44 views

Exiting a shell script if certain child processes exit

I have a Bash script that starts one web server, does some work, and then starts a second web server. I would like the script to exit, and for both of these servers to be terminated, if either server ...
0
votes
1answer
28 views

How to prevent .bash_history from being used to rebuild history

We use custom history files which get backed up per user. When someone does a history -c we notice that after they log back in there is history in the buffer again and it seems to come from ...
61
votes
5answers
194k views

How to append multiple lines to a file with bash

I am writing a bash script to look for a file if it doesn't exist then create it and append this to it: Host localhost ForwardAgent yes So "line then new line 'tab' then text" I think its a ...
6
votes
4answers
411 views

How can I use '*' to capture everything with exceptions

For example, I have files named A_1.txt A_t_1.txt A_ts_1.txt A_tsa_1.txt in a directory ~/admin/packages/. I am building a for loop to by globbing to A_1.txt for f in ~/admin/packages/*_1.txt ...
3
votes
2answers
3k views

difference between `for i in {1..$N}` and `for i in $(seq 1 1 $N) ` [duplicate]

I have the following in a script: #!/usr/bin/env bash ... for i in {1..$N} <loop content> The above doesn't work and is only executed once where i has the value {1..5} (if 5 was provided ...
0
votes
2answers
21 views

Listing numbered files using wildcard sequence with predefined range

I have a folder of numbered data files. I am trying to incrementally extract a predefined range of files. The range of files that I am looking for is predefined in two variables, ns and ne, which ...
0
votes
1answer
37 views

Few questions about realization of commands using bash scripts

I'm the newbie into scripting, so, please, sorry for annoying questions. I need to create bash script file, which after its launch does following. 1) Suppose after launching the script I enter the ...
1
vote
2answers
40 views

Extract zip files into directory based on pattern of zip name

I have these zip files: PLP_633555_2015-03-04_01-12-01.zip PLP_634562_2004-03-02_02-15-07_UBIC.zip PLP_563462_2008-05-02_01-21-03_UBIC_STOC.zip And I need each zip extracted into its appropriate ...
4
votes
2answers
316 views

How do I print the (numerical) ASCII values of each character in a file?

How can I print the numerical ASCII values of each character in a text file. Like cat, but showing the ASCII values only... (hex or decimal is fine). Example output for a file containing the word ...
3
votes
2answers
156 views

Ctrl-Backspace and Ctrl-Delete in bash

Putting on Debian 8.3 stty werase '^H' or on Arch Linux 2/2016 stty werase '^?' in .bashrc (for example) makes Ctrl-Backspace delete the last word in the terminal. Still it's not the same ...
1
vote
2answers
759 views

bash scripting : using expect

I am facing an issue when I run simply these commands. The remote server want to pass "yes" to add the key in RSA file because first time connection established with scp. commands are given below ...
1
vote
3answers
47 views

bash is not terminating

I'm trying some things with my shell. This includes the following command: kill $$ My expectation was that the shell would log me out and terminate itself. But instead the bash persists without ...
0
votes
2answers
58 views

Credit card number validation with bash

I have used the following regular expression to detect the valid card numbers. [2-6][0-9]{3}([ -]?)[0-9]{4}([ -]?)[0-9]{4}([ -]?)[0-9]{3,4}([ -]?)[0-9]{0,3}[^a-zA-Z] But it does not detect the ...
4
votes
2answers
2k views

Convert mysql count(*) to int in bash?

I'd like to execute this and check if count is 0, 1 or > 1 in bash. mysql -e "select count(*) from mydb.mydb;" The output is: +----------+ | count(*) | +----------+ | 0 | +----------+ I ...
1
vote
1answer
40 views

Detect number of /dev/sd_ 's on a computer by bash script

I am trying to add code to a Bash script (.sh) to detect the number of sd_ 's on a computer (ex. /dev/sda, /dev/sdb, /dev/sdc, etc.) and then save that number to a variable, and then use if statements ...
1
vote
3answers
67 views

Is there any way of speeding up this DNS script I made? [on hold]

Part of my work is doing a lot of different DNS lookups, so I created a script that displays the information that I need in a neat fashion. Problem is it's not very fast. Doing a bash -x I can see ...
0
votes
1answer
50 views

Validate user response in shell script

My shell script is working fine and the files are copying to the remote directory. However I need to check if my INPUT_STRING is starting with S and also check if the files are present in the ...
2
votes
2answers
26 views

Timeout with 'service network restart'

I have a script running on fedora 22 where I am restarting service network as part of a troubleshoot calling service network restart. I want to check if that command is taking too long to execute. If ...
1
vote
0answers
22 views

Problem with submenus

im trying todo a script with two menus, one with basic comands and the other passowrd protected with five more advanced commands but the script dont pass the first menu, i think that there is a loop ...
1
vote
1answer
33 views

timestamping history file causing erroneous lines in history command

I have .bash_profile setup to export to a history file: export HISTFILE=/root/history/.bash_hist-$(who -m | awk '{print $1}') Then I am exporting time stamps for the history command. export ...
0
votes
1answer
46 views

Using regexp_replace to replace single quotes around string but not within words e.g. can't

I'm using the below code from a bash script to replace single quotes from my title column in a postgres database with spaces. psql -U postgres -d my_database -c "UPDATE my_table SET title = ...
-2
votes
1answer
23 views

bash shell while loop is going beyond the conditional expression [on hold]

In my problem, it appears like j value and i value reach 6; where i should only run up to 5. Can someone please explain ? i=0; j=0; echo "values of $i and $j" > debug.txt; while [ $j -le 5 ] do ...
3
votes
2answers
52 views

What does “rotate the kill ring” mean?

In the readline info pages : info bash -n "Commands For Kill" M-y Rotate the kill-ring, and yank the new top. You can only do this if the prior command is C-y or M-y. Ì understand ...
11
votes
1answer
530 views

Is there any way to tell if a shell script was killed with signal 9

I have a bash script (called from a java program) that keeps getting killed. I always catch the signal 15 with trap but then some other signal comes along that I suspect is signal 9 but am in ...
0
votes
1answer
872 views

Run supervisord without root access

Hi I'm really new to writing scripts and I searched a lot but all that I've found is scripts with full access. I don't have access to the /etc. I'm working in a host in the cloud but I have limited ...
0
votes
2answers
107 views

Different results invoking bash directly or via soft link

On my Red Hat Linux system /bin/sh is a link to bash $ ls -l /bin/sh lrwxrwxrwx 1 root root 4 Sep 27 13:17 /bin/sh -> bash Running this contrived test program directly gives me the expected ...
4
votes
4answers
217 views

Prefer file types in command line

Often I have to annotate multiple pdf documents using xournal. If I start with a directory of "fresh" pdf files, I just open them all with xournal: for f in *pdf; do xournal $f&; done When I ...
8
votes
2answers
195 views

Why is the ability to define functions in an environmental variable not a security risk in itself?

As I understand it, generally it is considered safe to let anyone provide information that will be stored in an environmental variable. The shellshock vulnerability is an issue here because it means ...
20
votes
8answers
39k views

Test if there are files matching a pattern in bash

I am trying to write an if statement in bash to test whether there are any files matching a certain pattern. If there is a text file in a directory it should run a given script. My code currently if ...
13
votes
3answers
4k views

bash find xargs grep only single occurence

Maybe it's a bit strange - and maybe there are other tools to do this but, well.. I am using the following classic bash command to find all files which contain some string: find . -type f | xargs ...