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

0
votes
1answer
29 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 ...
14
votes
1answer
304 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
2answers
22 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
40 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
1answer
47 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 ...
1
vote
3answers
49 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
65 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
4answers
50 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
2answers
65 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 ...
3
votes
2answers
36 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 ...
0
votes
1answer
47 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 [closed]

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 ...
0
votes
1answer
51 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 ...
0
votes
2answers
61 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 ...
4
votes
2answers
56 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 ...
1
vote
1answer
34 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 ...
1
vote
3answers
69 views

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

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 ...
1
vote
1answer
20 views

Logins in an interval?

How can I get who was logged in in an interval? I tried last -t, but it was not what I was looking for. I want to get who was logged in between May 11. 10:00:00 and May 15. 22:00:00 for example.
0
votes
0answers
39 views

script to delete files when it cross limit size

I want to make a script which delete files when it cross 70% usage. In directory there are logs files has 9.6 MB size. I want that if directory cross 70% then it find oldest files and delete them. ...
0
votes
1answer
29 views

small error but seems annoying [duplicate]

I have error (command not found). I am newbie here. so what is the easy solution and explanation for this error?
3
votes
2answers
63 views

How can I parse an ini file whose values may contain certain characters?

I have looked at a couple bash ini parsing scripts and I've seen this one used a few times here so I'm trying to see if it will work for me. It looks like it reads the ini file line by line multiple ...
1
vote
1answer
29 views

bash script trap for exit and err and logic for difference

I have a bash script and would like to add in the ability to trap for both EXIT and ERR conditions. The structure is currently trap cleanup EXIT function notify(reason) {} function build {} function ...
0
votes
1answer
32 views

Bash script SFTPing into remote server and downloading files, cd into proper directory on local machine

I have a cron on my Ubuntu server that runs this bash script daily: #!/usr/bin/expect -f spawn sftp user@ip expect "password:" send "password\n" expect "sftp>" send "cd remote_directory\n" expect ...
1
vote
2answers
45 views

How can I add a filter to my grep script to NOT include a string?

I'm working on a script that will separate the Registrar information from a domains whois. So far it's working enough but there are a few things that I want to remove in order for it to be a bit ...
3
votes
1answer
51 views

When did bash's shopt huponexit start defaulting to off?

On Monday morning, I logged into a box with ssh and ran the following command: tail -f /var/log/foo/bar.log | grep something_interesting & At some point later in the day, I logged out by ...
1
vote
1answer
56 views

Get the canonical path for a command

I'm writing a script that needs canonical path of certain commands. Since there could be symbolic links pointing to the actual commands, I use readlink -f to get the canonical path. But I'm not ...
1
vote
1answer
36 views

bash script read array outside loop

This is my first attempt to write a bash script and I'm unable to read array outside for loop. What I'm trying to do is.. store name of all files from /MyDir in an array. Check if there is process ...
1
vote
1answer
30 views

export (save) and import (source) shell variables

I need to save environment variables to a file and (later) a process should import them. I need this to workaround a program fooprog that nullifies the environment before executing a barscript, and I ...
-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 ...
2
votes
3answers
55 views

Use a wildcard in directory path

I'm trying to write a bash script where part of a directory is a long, unknown string. I know the first part of the directory name. How do I combine the known string and the wildcard in the path? As ...
1
vote
7answers
65 views

Rename files add dashes after fourth and sixth characters

I have some files such as: 20150716_something-here 20150716_something-heretoo 20150716_something-hereaswell They need to be renamed as 2015-07-16_something-here 2015-07-16_something-heretoo ...
3
votes
2answers
40 views

bash combining wildcard expansion with brace expansion

I'm trying to expand a string involving a wildcard and a collection of extensions specified within braces. Nothing seems to work as the example below illustrates. the variable firstList expands ...
3
votes
1answer
60 views

What is the overhead of using subshells?

Hopefully this question is not too generic. I am very new to shell scripting and I come from a computer architecture/non-scripting programming background. I have noticed on the scripts at my work that ...
1
vote
2answers
42 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 ...
0
votes
1answer
26 views

Card Number regular expression help [closed]

I have used the following command+REGEX to list all the files contain card numbers in a set of files. grep -r -l -e '[3-6]\d{3}([\ \-]?)\d{4}([\ \-]?)\d{4}([\ \-]?)\d{3,4}' * I have tested this ...
0
votes
1answer
46 views

Why would this script work with bash on Kali, but not with bash on Xubuntu?

I have a script that I made when I was at home on a Kali virtual machine. It works perfectly there, but now I'm at work on my Xubuntu install and it's not working at all. The exact shell that I'm ...
3
votes
3answers
73 views

Replace a long string with the sed command: Argument list too long error

I'm trying to execute this command sed -i -e "s/BASE_64/$BASE_64/" FILE_NAME where $BASE_64 is a base 64 representation of a file content. sed gives me an error since the string is too long. ...
0
votes
0answers
23 views

What is the purpose of the symbolic `git` link inside the `/data/git` folder of the gogs docker installation?

Initially I asked this as a more generic question here: Is there a purpose to a symbolic link that points back to the directory containing it? Since it relates to gogs specifically I'm asking for a ...
2
votes
1answer
46 views

Is there a purpose to a symbolic link that points back to the directory containing it?

When Gogs docker installation is run it creates a symbolic link /data/git/git that points back to the parent folder: lrwxrwxrwx 1 1000 1000 9 May 13 19:37 git -> /data/git I'm ...
0
votes
3answers
69 views

insert variable text after another variable text on a specific line

I am trying to insert variable text after another variable text on a specific line. Below is my attempt so far, as far as I can tell, if I can escape the quotations in awk so that the variable can be ...
0
votes
1answer
61 views

How to write bash script while using command as condition in if statement?

I am writing a bash script to process input from html form. I have two issues which I can't seem to be able to figure out. I am a beginner to Unix. First problem is that I can't get my if statement ...
1
vote
1answer
74 views

Script fails, but copy and paste from script works

I made a script to check the computer's processor count and then change all references of the processor number in another script in accordance with that.  I tested it first by copying and pasting it ...
3
votes
1answer
56 views

What does !# (exclamation hash), !$:r:r (exclamation dollar colon r), !#:t (exclamation hash colon t) mean in the below bash commands?

I have been trying to install a Nagios package and stumbled upon these weird bash expansions on a guide here. Can someone help me understand what do the expansions mean? A wiki link would also be ...
1
vote
1answer
44 views

Extracting files to current directory

I want to find and tar/archive all my scripts ending .sh so I wrote something like that: touch ~/archive.tar; find ~ -type f -name '*.sh' -exec rvf ~/archive.tar {} \; The problem is that after I ...
1
vote
2answers
38 views

awk + how to append list in file

I have the following list in file more file.ex efifc1a hygg4a hdy5d nhdw4s wesf3a fjfhyr jfhg gsfar how to append any second list after the first list and any third list after the second list ...
0
votes
0answers
103 views

Start vino-server in Ubuntu 16.04 lts

I'm trying to raise vino-server in Ubuntu 16.04 but I could not. I am using this script and let me start by terminal: # /etc/init.d/vino-server.sh start but not as a cronjob: @reboot ...
2
votes
1answer
41 views

redirect split output

I split a gz file using gunzip piped to split: time gunzip -c file.gz | split -l 500 -d -a 4 - pref_ Which generates the following files: pref_0000 pref_0001 I'd like to pipe those files to zip ...
0
votes
1answer
33 views

Is using env and export the same thing?

I'm wondering whether this (From https://www.digitalocean.com/community/tutorials/how-to-read-and-set-environmental-and-shell-variables-on-a-linux-vps): env VAR1="blahblah" command_to_run ...
0
votes
1answer
32 views

User “read” command while executing remote scripts over ssh

Let me explain my situation first. I have an alias in .bashrc: doscript () { ssh root@server$1 -p2202 "bash -s" < ~/scripts/$2 $3; } I have a script, that basically consists of several actions ...