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

2
votes
1answer
40 views

Why doesn't grep give me the all found strings?

I have txt file whose inside there are 8 times "ATOMIC_POSITIONS" string and when I'm trying to write each one of them with ; AtomicPos=$(grep -n "ATOMIC_POSITIONS" hw1_out_si_wire.txt) echo $...
0
votes
2answers
33 views

How can I assign the last element of an array to a another array?

Let say I have an array $Info whose elements are ; ! total energy = -1090.13343774 Ry ! total energy = -1090.20757070 Ry ! total energy = -1090....
1
vote
1answer
48 views

Script to send mail using function

I am trying to write a bash script with a function which you use to send an email from the command line to an address and include a Cc address, a subject line, and an input file. For example, if the ...
1
vote
3answers
39 views

Extending Linux terminal Program [closed]

Any quick ideas on how to write a program that extends the terminal's basic functionality? I want to do everything the terminal does but additionally do some custom processing on whatever the user ...
2
votes
1answer
21 views

Strings from two distinct arrays not matching?

I'm trying to filter one array from another array. That is, I'm trying to create a third array with a logical not-intersection. The best I can tell, it appears this block of code never matches, and ...
1
vote
1answer
43 views

How to add numbers in many arrays

I have a file with many arrays, which has "identifiers" numbers in the first column. So I need to sum the numbers located in the second column based on that "identifiers" . An example of the input: ...
-4
votes
2answers
101 views

What is wrong in this code? [closed]

The code is ; cm=$1 nm=$2 case $cm in "out") declare -a en declare -a inf ec=$(grep -n "! " hw1_out_si_wire.txt) IFS=$'\n' en=($ec) lst=$((${#en[@]} -1)) IFS=' ' inf=($en[$lst]) echo " Energy: ${inf[...
1
vote
1answer
44 views

Will these commands return the same output on different Linux distributions? [closed]

I am writing a monitoring script. I am running it on a specific machine, and it works. It is planned to be ran on several Linux machines, not bound to a single distribution. Here are the commands and ...
1
vote
1answer
69 views

Bash Function Parameters - Spaces in Filename [duplicate]

I know there are rules for quoting parameters, but no matter what I try, I can't seem to figure out how to make this work. I have a function that takes a single filename as a parameter, then uses ...
0
votes
1answer
55 views

Bash script to install package if already not installed (From a directory with many packages) - Fedora 17

I have a directory full of rpms (And their dependencies). Currently I am executing yum localinstall ./packages_directory/*.rpm to install all packages in there. It automatically skips the ones already ...
-1
votes
1answer
67 views

How to compose a list of all the executables that are used in a bash script?

Executables as a general term for: common binaries scripts I suppose it can be done with some fat regex, matching start of new lines, conjunctions like && and ||, inline after ; etc...but ...
1
vote
4answers
112 views

Bash script to check if a file is modified or not

I try to write script to check if a file was modified or not. If it did, it should echo "Error!", if not - script keeps running. My script #!/bin/bash date=$(stat -c %y)$1 while true do ...
2
votes
1answer
66 views

substring removal in find -exec

When using $ find . -name string~ -exec cp {} FOO \; is there a way to use {} in FOO to remove the tilde character as we usually do with bash substrings e.g. : $ echo ${string%substring} I ...
1
vote
4answers
91 views

Why is this code not working?

I'm trying to take such a output like; $ sh mod-date-pattern.sh sun The file sun1.txt was modified on 2007-10-01 at 01:26. The file sun2.txt was modified on 2007-10-01 at 19:10. The file morning-sun....
1
vote
4answers
57 views

How to open or list all files whose names match two patterns in Bash

Suppose that I have a directory with thousands of files; how could I open all files whose names contain the strings "red" and "green"?
6
votes
2answers
110 views

Why does Bash ignore SIGINT if its currently running child handles it?

The following Bash loop stops if I interrupt it with ^C: (while true; do sleep 5; done) The following, however, does not: (while true; do aplay test.wav; done) The difference, from what I can ...
2
votes
3answers
66 views

Mysql output format in Bash Script

I'm writing a bash script where I'm using mysql query in that script where the format which I'm getting is quite different. Query: root@debian:~# mysql -u root -ptoor super_market -h 0 -e "select * ...
1
vote
1answer
47 views

Combining Bash Script and Script Resources into One Executable

When trying to execute a bash script, it is often execute inside some directory, and requires access to local resources. I was wondering if there was a way to combine both the bash script and the ...
2
votes
1answer
17 views

Sending notifications from irssi to wmii

So this is two questions in one. Simply setting PROMPT_COMMAND='echo -ne "\033]2;BLAH\007" will change an xterm titlebar to the string "BLAH", even under wmii. Of course, I can also change the ...
0
votes
2answers
25 views

Preventing command substitution from evaluating when appending to a file

How can I stop the eval statement from evaluating when it's being appended to a file as part of a cat << __EOF__ command? TL;DR I manage services on a large number of Linux servers. ...
2
votes
1answer
47 views

Putting subshell in background vs putting command in background

I have two bash scripts that try to check hosts that are up: Script 1: #!/bin/bash for ip in {1..254}; do ping -c 1 192.168.1.$ip | grep "bytes from" | cut -d" " -f 4 | cut -d ":" -f 1 & ...
0
votes
1answer
27 views

bash script controlling ffmpeg to convert from mkv

Help me debugs this script to create control ffmpeg from a bash script. for f in $FILES do INPUT_MOVIE=`basename "${f%.*}.mkv"` OUTPUT_MOVIE=${MOVIE:1} OUTPUT_MOVIE=${OUTPUT_MOVIE:0:2}") ...
0
votes
3answers
53 views

How to remove poorly named file [duplicate]

I was using pscp to copy files from a Windows machine to a Linux machine. I accidentally got the path wrong and now there are files that I can't seem to remove. I think it is because of the slashes in ...
0
votes
1answer
42 views

sum of numbers located in different rows using awk

The following lines sum numbers located in the row #2 and row #3 , row #4 and row #5, row #6 and row #7 and so on (so, sum in a consecutive way). awk ' NR==1{$1=$1; print; next} !(NR%2){split($0,a);...
7
votes
4answers
128 views

How do I determine if a program is running when I start a shell and start that program if it is not already running?

When I start a shell, in my case bash and/or zsh, what lines do I need to add to .zshrc and/or .bashrc to check to see if a program is already running, and if the program is not already running, start ...
-1
votes
1answer
31 views

Evaluate a unix command within for loop [closed]

I wish to print from i.res to POSCARi+1. i.res are files with names 1.res, 2.res, 3.res, etc. These files are sitting in the working directory. POSCAR(i+1) are files with names POSCAR2, POSCAR3, ...
2
votes
2answers
20 views

Simple Korn shell script needed to list out all files created/modified after tidemark date

How to list out all files created/modified after a particular tidemark date? If my tidemark date is '30-May-2016 08:06:49' then I need all files/directories generated/modified after that date&time....
0
votes
0answers
50 views

zsh function: maximum nested function level reached

Consider this simple function I am trying to add in my .aliases (dnf is Fedoras newest replacement of Yum): function abc() { dnf search something } It works well on Bash but I get the following ...
3
votes
0answers
52 views

Can bash to syntax highlighting, git info prompt and autocomplete based on the middle of a word?

I'm using prezto framework for zsh and started wondering if I really need zsh. Main features I really dig are syntax highlighting for commands, fancy prompt when in a git repository and the ...
0
votes
0answers
20 views

Why is bash ignoring my colours? [duplicate]

I have my ls colours set in my .bashrc as #Bash colours 120 TERM='xterm-256color' 121 122 # Directory Colours 123 LS_COLORS=$LS_COLORS:'di=36' ; export LS_COLORS #Cyan 124 #File Colours 125 ...
-1
votes
0answers
22 views

bash script to copy and rename directory and files therein

I start with a single directory with input and command files in them in such an order: unit.1.2 //1 is variable A, 2 is variable B -unit.1.2.in -unit.1.2.cmd I need to copy and rename ...
-1
votes
2answers
164 views

How to sum many numbers inside 2D array using awk

I need to sum numbers located in a file like this one: column1 column2 column3 row1 a(1,1) a(1,2) a(1,3) row2 a(2,1) a(2,2) a(2,3) row3 a(3,1) a(3,2) a(3,3) row4 a(4,1) ...
5
votes
5answers
334 views

How safe it is to output to <dir> simultaneously with rm <dir>/*

Sometimes I need to remove all the contents of a directory and create new files there. Can I do something like this and expect all new files to remain intact: % rm -rf regression/* & ( sleep 10 ; ...
0
votes
2answers
76 views

Kill shell script process by name

I have a script running in background like this: nohup /tmp/a.sh & If the script is running for more than 5 mins, I want to kill it. -bash-3.2$ nohup /tmp/a.sh & [1] 2518 -bash-3.2$ nohup: ...
0
votes
0answers
23 views

Bash Script to start a service on Ubuntu Linux 16.04

Does the following Ubuntu 16.04 bash script command: exec /usr/lib/mono/4.5/mono-service.exe \ /home/frank/Debug/My_Camera_Recorder.exe "$@" >& /dev/null start the My_Camera_Recorder ...
14
votes
3answers
2k views

bash: I broke [[ < ]]

I was writing a bash script and suddenly this behaviour started: [[ 1 < 2 ]]; echo $? # outputs 0 [[ 2 < 13 ]]; echo $? # outputs 1 but -lt works soundly: [[ 1 -lt 2 ]]; echo $? # outputs ...
1
vote
1answer
57 views

stderr not redirected to stdout

I run a TACACS+ server which sends debug information to stderr. As I would like to grep specific data from this debug information, I redirected stderr to stdout: tac_plus -f /usr/local/etc/tac_plus....
0
votes
0answers
23 views

To forward-search in Raspbian's Bash?

Keybinding CTRL-S is enabled by default in Debian/Ubuntu/OS X bun not in Raspbian. I can enable the reverse-search by in $HOME/.bashrc, which disables XON/XOFF, but it does not help with the forward-...
3
votes
1answer
641 views

Grep that shows the pattern line and the matching line

Suppose I have these two files: 1. Locus_1 univ Locus_2 anc Locus_3 cat 2. university GO:000001 impromptu GO:000002 advanced GO:000003 inheritance GO:000004 I want to do a grep -f of the ...
1
vote
1answer
32 views

Renaming folder using a txt file [closed]

I'm working in my terminal using bash trying to rename the folders: 1 2 3 4 5 I'd like to rename them according to a.txt file: a 2 c 3 d 5 e 1 b 4 The order in the .txt file is completely ...
0
votes
1answer
22 views

xdotool sleep 1 vs sleep 1, any difference?

Is there any difference between these two sleep commands: Either: xdotool sleep 1 Or: sleep 1 Example: #!/bin/bash while : do xdotool mousemove --sync 1000 500 xdotool click ...
0
votes
3answers
52 views

Implementation of process substitution, and concurrency in process substitution

Bash Manual says Process substitution is supported on systems that support named pipes ( fifos) or the /dev/fd method of naming open files. Does it mean that process substition is implemented ...
0
votes
1answer
32 views

Different hostname / prompt is shown after logging in as root

[mayur@centos ~]$ su Password: [root@centos mayur]# I want it to be "centos" only. How to do it?
1
vote
1answer
33 views

Do commands in command substitution, process subsitution and in pipeline accept stdin inputs?

I expect cat in the following command substitution, process substitution, and pipeline to accept stdin input, but Why does it not output anything, after I provide stdin input hello $ echo $(cat) ...
0
votes
2answers
38 views

How to extract first and last lines in a file? [duplicate]

File1 Sergio Lionel Luis Andreas Gerard I want my stdout to have just Sergio Gerard How can I do this using the tail command and piping?
4
votes
2answers
67 views

Rename Multiple files gzips them and delete older than 10 days

I'm new to Linux/Unix and slowly learning it step by step. Unfortunately on today’s job interview was surprised by a task to do (which of course I didn’t know). I was asked to prepare a bash script ...
1
vote
0answers
36 views

Bash script, string spaces handling [duplicate]

I'm writing a script that will automatically sort my albums on my NAS server and encountered the following error. Whenever I have a space in an album name I'm getting an error. Albums can be either ...
0
votes
3answers
26 views

Is it possible to tab through the commandline history for a particular command?

For example, can I see all the previous parameters I passed to the command ssh (i.e. all the server addresses I passed as a parameter when calling ssh)? This is going to be something similar to the '...
0
votes
1answer
16 views

How to specify PRAGMAs in an sqlite3 command line call?

I create a SQLite file like this: sqlite3 output.db < myinserts.sql Unfortunately it takes hours, so I want to speed it up by using the following PRAGMAs: PRAGMA synchronous=OFF PRAGMA ...
2
votes
1answer
30 views

sed whole string replacement not working

I have two scripts ins.sh and variable.sh. variables.sh holds various key-value pairs. ins.sh #!/usr/bin/env bash set -e # Exit upon error # This script generates a 64-bit system source variables....