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

3
votes
2answers
43 views

Read a password securely from within process substitution?

Related: Securely feeding a program with a password How to read from stdin in process substitution? Process substitution and cat: can't read stdin I've read the above questions and I still ...
0
votes
0answers
7 views

how to find keycodes for Aterm backspace, and deletekey

I downloaded compiled, and installed aterm 1.0.1. and I cannot get the backspace or delete keys to work. I've tried everything I've found on the net about it. aterm*backspacekey: \010 ...
4
votes
2answers
42 views

From bash, spawn two processes and exit both if either sibling exits

From bash, I am spawning two processes. These two processes depend on each other. I want both to exit if either one dies. What is the cleanest way to do that? Currently I have the following: # start ...
2
votes
1answer
71 views

Strange bash script behaviour

I have two bash scripts, which are binary identical, have the same permissions, are unique on my drive and are not found in sudoers. Still one passes the uid test for root, the other one not. If I ...
3
votes
1answer
39 views

Echo text as suggested prompt in bash

Is it possible to change text that appears after $PS1. It is what user inputs. I want to suggest some command hereafter my_function is run. Of Course I should be able to modify/delete it using ...
0
votes
3answers
24 views

Implementing a command that executes the given command in a certain path and returns to the current path

my code: execInPath() { prev_dir=${PWD##*/} cd $1 shift res=$($@) cd prev_dir echo res } alias path=execInPath $ path ~ ls gives: bash: cd: prev_dir: No such file or directory (and the files in my ...
1
vote
2answers
39 views

Copy output of curl to file

I'm running raspbian and using this bash script to take a photo every minute and upload it to my FTP server: #!/bin/bash while [ 1 ]; do DATE=$(date +"%Y-%m-%d_%H_%M_%S") raspistill -q 10 -th none ...
0
votes
4answers
49 views

Find files using shell script

I have the below script which looks for the file in the current directory and evaluates to true if the file exists in the directory and evaluates to false if it does not #!/bin/bash printf "\n Please ...
0
votes
1answer
23 views

Using if and find together

I'm trying to write a script that echos "success" if it finds .trc files older than 5 days in a directory. However I'm getting a full_path_trace': No such file or directory error even though my ...
0
votes
0answers
34 views

Bash script is not executing after reboot command Ubuntu 14.04

I've tried using a /etc/init.d/ script, an upstart script, crontab, etc. None of the above are causing the script to execute on boot. The service I am attempting to automatically start on boot is ...
1
vote
1answer
37 views

Read each line - BASH

my goal is to store each foliated line (actually each rule) into an array. My output: Chain INPUT (policy ACCEPT) num target prot opt source destination 1 ACCEPT ...
0
votes
0answers
28 views

Process being stopped randomly

I made a script to manage a TS3 server. The script runs 'cd '.$ts3location.';/bin/bash '.$ts3script.' status' where $ts3location is the full directory to the server and $ts3script is ...
1
vote
3answers
103 views

Split comma separated list ignoring commas within matching {}

I want to split a csv, but ignore any commas within matching curly brace groups, and loop through each of the list members. The code below works great but does not consider commas within curly brace ...
1
vote
1answer
63 views

Looping through lines in file using bash and passing to variable. Resulting variable is not the same value as file, why?

I have a bash script (just doing some simple log file pattern matching) that I have had running in a cron for a few years. Recently it broke and started returning odd results. Upon digging into the ...
0
votes
4answers
34 views

Run multiple piped grep commands from a list in bash

As part of my security job, I analyze dozens of Google Chrome history files each day using sqlite3 over SSH. There are a few dozen authorized "safe" sites each user is allowed to navigate to. For my ...
5
votes
5answers
340 views

BASH: how to pass a default argument if no arguments after the first were passed

I have a bash script with a case statement in it: case "$1" in bash) docker exec -it $(docker-compose ps -q web) /bin/bash ;; shell) docker exec -it $(docker-compose ...
5
votes
1answer
337 views

Using 'ping', 'cut' and 'tee' together

So, I understand that by using 'tee' I can redirect the output of a command such as 'ping' to stdout as well as a file. For example: > ping google.com | tee somefile This would display the ping ...
1
vote
1answer
76 views

How to write bash script without using sudo in it?

How can I write a gem install or apt-get install in bash without letting it use sudo? #!/usr/bin/env bash apt-get update -y apt-get upgrade -y gpg --keyserver hkp://keys.gnupg.net --recv-keys ...
-1
votes
0answers
42 views

Professional IDE for editing bash script [closed]

To develop bash scripts for Linux systems. What are the good IDEs (Syntax suggestions available IDEs) to use as professionals ? I am using Basic editors like Vi, gEdit, Nano etc.. When we are ...
1
vote
1answer
33 views

Double quotes issue in bash script

I have a shell script I am trying to get working. I need the output to be a certain way and I know I'm just not escaping the characters correctly. script: #!/bin/bash set -x DATE=$(date ...
1
vote
1answer
37 views

Test length of string in file

I am not sure if I am using my argument correctly. I would like to pass in a argument which is a text file containing a string. When I run this script, it always enters the if statement even when the ...
1
vote
2answers
75 views

How do I check if an IP-address or a network is contained in other network in Bash?

I need to check if an IP-address or a network is contained in other network, e.g. if '10.1.2.3' is in '10.0.0.0/8' or if '10.1.2.0/24' is in '10.0.0.0/8'. Currently I use python for this, e.g.: if [ ...
0
votes
1answer
17 views

grep -E with parameter doesn't work

If I use -E option for grep from a script I'm unable to user variables. For example: txt file: word nir asd b asd text script: #!/bin/bash PARAM=b cat txt | grep -E 'nir.*${PARAM}' The script ...
3
votes
1answer
36 views

How do I turn off redirection once I've turned it on? [duplicate]

I found a great solution at Redirect all subsequent commands' stderr using exec. I used the example: exec > >(tee $somelog) 2>&1 ...and managed to get everything to tee great. ...
3
votes
3answers
39 views

How to pipe data from one command to another command which allows only a file as an argument?

I have some arbitrary data as an output of a command (e.g. a fragment of a binary data put out using tail). I want to feed it to another command/program which allows only a file as an argument (e.g. ...
4
votes
3answers
60 views

Force POSIX mode

Brace Expansion, eg {a,b,c} is not defined by POSIX. I would like to run my shell in POSIX mode. With Debian this is simple enough: $ bash -c 'echo {a,b,c}' a b c $ sh -c 'echo {a,b,c}' {a,b,c} ...
0
votes
0answers
81 views

How to detect when apt-get requests cdrom?

I'm using debian 8 jessie. I don't use a physical CD-drive, there is no /dev/cdrom. I have DVD-1 and DVD-2 iso files of the operating system. I mounted DVD-1 iso at /media/cdrom01 and DVD-2 iso at ...
7
votes
1answer
133 views
+50

Need help improving my Bash script

I need some help improving my Bash script so that it runs flawlessly without having issues. This script uses ds4drv in it and it has some issues that I'm unsure on how to correct. First issue is that ...
0
votes
0answers
18 views

Can I make history not print any timestamps for commands that were run before I enabled that option?

If you run history, it outputs the current date before commands that were run before I enabled timestamps, is there anyway I can make it ignore that? For example, if my .bash_history looks like this: ...
0
votes
1answer
30 views

Why not display characters which I typed in tty? [duplicate]

I pressed CtrlAltF1 to enter TTY1. I worked a while mainly on vim, then my shell (bash) stops echoing. If I type echo abc it does not get display. Instead I get a screen like this: How do I fix ...
-1
votes
2answers
38 views

Grep expression with spaces - BASH

I would like to grep ACCEPT, DROP, REJECT as is shown below. -P INPUT ACCEPT -P OUTPUT DROP -P FORWARD REJECT I executed iptables -S | grep -E '\-P INPUT|\-P OUTPUT|\-P FORWARD' | awk '{print $2}' ...
1
vote
2answers
28 views

BASH - Associative array - getting the value of the key in the final element

I have created an associative array as follows: declare -A test_array test_array[0,0]="1" test_array[0,1]="A" test_array[0,2]="11" test_array[0,3]="AA" test_array[1,0]="2" test_array[1,1]="B" ...
1
vote
0answers
29 views

Bash one liner not looping [duplicate]

I am trying to loop through a file to run commands remotely via SSH but its only sending the first command and stopping. while read a b c; do ssh root@$remoteserverip "/usr/bin/mysql -e \"grant all ...
1
vote
0answers
13 views

Trap error on remote server

I have a script that run commands locally, and also execute commands on a remote server via SSH. When an error occurs on the local server, I am able to trap it, send an email and exit the script. But ...
0
votes
1answer
28 views

Why does piping filenames into VIM break bash when I return to the shell?

I searched for a few files with find and I wanted to open all of them in tabs in Vim. So I tried this: find . | xargs fgrep -l myExpression | xargs vim -p This worked great, except when I was done ...
1
vote
1answer
42 views

script Multiple Commands

I have a PHP script I'm running from Cron. I want to save its output to file, but also want to save the shell output to a different file. Ideally, I'd like to have this in one line. As such, I tried ...
1
vote
2answers
46 views

Add columns to a text file with set spacing in Bash

I am setting up a malware zone file in DNS which will point all hosts to a specific IP. The file is simply a list of hostnames. This is what I have now: googlle.in ...
-1
votes
5answers
80 views

Bash script to insert letter based files into directories [closed]

I'll start by saying I'm a complete novice to this. So basically, what I need to do is create a script that makes 15 directories (named from 1 to 15) and inside each directory I have to have a letter ...
3
votes
2answers
53 views

Getting the full path name of a given directory

Suppose I'm in /path/to/dir. Within this dir is another dir called subdir. Is there a command I can issue which outputs the full path to subdir, no matter how it is identified? For example: $ cmd ...
1
vote
1answer
31 views

echoing a value from a BASH function after a command has been run in the background

I am trying to run the following, as a test for something else: function echo_test { sleep 60 & > /dev/null returnpid=$! echo $returnpid } pidthatwasreturned=$(echo_test) echo "This ...
0
votes
2answers
37 views

Bash Script execute command as user

I'm just wondering if it's possible to execute a command inside a bash script as a specified user and supply the password in one string. At the moment I have COMMAND="${DIRECTORY}/script.sh" su -c ...
0
votes
1answer
14 views

alternative approach for selective deletes from rsnapshot tree with find?

I'm looking for a generalizable solution to this problem, 'cause I'm sure it will come up again. I have a client that does medical research. Periodically we have to remove the datasets provided by ...
6
votes
2answers
392 views

Why do here-documents attempt shell substitution even on a commented line?

I wanted to see how some ASCII art looked in terminal so: $ cat <<EOF ...
0
votes
0answers
15 views

Setting anacron on mac

I set cron to run script every day using env EDITOR=nano crontab -e where I wrote something like this @daily path/to/sript.script Now I want to use anacron to be sure that script is going to be run ...
1
vote
2answers
33 views

Is there any command that mimics the double tab list in bash? [duplicate]

I would like to get the same possible autocomplete list as hitting [Tab][Tab] in bash but with a command. Is there anyway to do that?
0
votes
1answer
33 views

Simple if/else statement not working [duplicate]

I have been trying for a long time to get this basic bit of code to work in a shell script, but to no avail, the code doesn't work! read dec if [ dec="Y"]||[dec="Y"]||[dec="y" ]; then let repeat=1; ...
0
votes
2answers
40 views

Echo a string with a variable in it without expanding/evaluating it [closed]

I've searched everywhere. Tried echo and print. Tried single and double quotes. But I have parsed data and assigned it to a variable and would like to then evaluate it for if there is a variable ...
-1
votes
0answers
27 views

dump non formated output of commands to csv file

I have some commands with which i can get list of VMs running on hypervisors. I redirect that output to some file.txt and use while loop to read each line from file.txt and execute two more commands ...
1
vote
0answers
20 views

Bash tab completion not working within symlinked directory

I'm working with Bash 4.2.46 on RHEL7 with the bash-completion packages installed, but I seem to have found an odd corner case where tab completion doesn't seem to work as expected. I have a set of ...
1
vote
2answers
43 views

How to define alias for non interactive/non login shell?

I have a user (zabbix) with shell set to /sbin/nologin. The user's home is /var/lib/zabbix and I inserted alias curl='curl -k' into ~zabbix/.bashrc. However it does not work when I (for testing ...