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

5
votes
2answers
348 views

nested double quotes in highly-voted one-liner

A StackOverflow answer with > 3.5K votes features this one-liner for assigning to DIR the directory of the current bash script: DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" I'm ...
0
votes
0answers
38 views

tailing file in new terminal window

I have the following two bash scripts (perhaps they can be condensed into one). // pre-tail.sh #!/usr/bin/env bash open -b com.apple.terminal `dirname $0`/tail.sh // tail.sh #!/usr/bin/env bash ...
1
vote
1answer
69 views

Exec process with custom env

I'm programmatically spawning processes in bash. I need to be able to pass in arbitrary environment variables and commands. To achieve this I'm running /usr/bin/env and then calling bash -c. Sometimes ...
2
votes
4answers
241 views

How to match “4.4” from `uname -r`?

Pseudocode [ `uname -r` =~ ^4\.4.*$ ] && echo "yes" which is, however, unsuccessful in all cases. The uname -r command gives things like 4.6.0-040600-generic as an output.
32
votes
2answers
1k views

Difference between “command not found” and “no such file or directory”?

For example: $ node -bash: /usr/local/bin/node: No such file or directory $ foo -bash: foo: command not found What's the difference? In both cases, node and foo are invalid commands, but it seems ...
0
votes
3answers
63 views

How do I find the string after a regexp on a single line of text?

I have a text file containing a very long line of JSON data and I need to extract the value of some field.  I realize the easiest way to do this would be to use jq or grep -o; however, I am on a ...
0
votes
1answer
27 views

What's the usage of rbash?

I've read some questions about the difference of TTY, console, terminal, etc here and on Askubuntu. Someone mentioned restricted shell, like rbash or bash -r. I first fought it is good to give ...
0
votes
0answers
7 views

Why doesn't wpa_supplicant work when using crontab job?

I am writing a script that is installed via a crontab job. The point of the script is to locate a specific AP and connect to it on start up. The script will log its progress to a text file called, "...
0
votes
1answer
44 views

help to analyse a log file

How does sed 's/\[//' work in case of analyzing log files for the time stamp fields? I found a solution online and I saw this line "$(head-1 "$1" | awk '{print $4}'| sed 's/\[//')". Can someone ...
0
votes
2answers
188 views

Why does my command: “rm -rf *” not delete all the files in a directory? [duplicate]

Most of the files are gone, but I'm still left with these two files: ".RData" and ".Rhistory" Why is this the case? I'm working with R, but I don't know what those files are. Afterwards, I can ...
0
votes
1answer
34 views

What is the step by step procedure to analyze automatic logout on a linux ( ubuntu) system

After I login using UI, I am logged out. Shall I start by looking on log files ? Which one. I have root authority on the system. Is putting a "pause" or "sleep" in a script file that gets executed ...
15
votes
1answer
746 views

How to terminate a TCP connection established by bash itself?

I have used exec 3<>/dev/tcp/192.168.0.101/6435 to establish a TCP connection with 192.168.0.101:6435. And I have received as well as sent a few messages with the pipe command. Now, I want to ...
-5
votes
3answers
97 views

How to add all the numbers of a specific column in UNIX without using awk command?

Let us take a sample file with the contents below, an expense report containing items and their prices: $ cat file Item1,200 Item2,500 Item345,900 Item20896,800 Item111,600 Now, a friend challenged ...
1
vote
1answer
25 views

How to reset bash bindings? [duplicate]

I wanted to create bash binding so that ctrl+backspace deletes word in terminal. But I somehow ended up screwing up my backspace and now it doesn't work, it outputs character. I know I can list all ...
3
votes
1answer
35 views

Messages on new terminal after using nohup

I'm trying to run a few commands asynchronously on a login script (.bash_profile). When I open a new terminal, I see messages like this. They also show up when I log onto a system over SSH. Last ...
1
vote
2answers
131 views

Sorting files using a bash script

Thank you very much for reading this. I am very new to bash so I need your advice in the following: I want to write a bash script that would read a file with 2 columns f 2 g 1 s 4 d 5 f 2 g 5 ...
1
vote
0answers
11 views

Avoid delays from network calls in logon and logoff scripts

I'm trying to tune some scripts in my test environment. My test environment is specialized and it exists to test software. The software includes Botan, Cryptlib, Crypto++ and OpenSSL. Whenever I log ...
0
votes
2answers
36 views

variable interpolation in shell script

I wrote the following shell script for a pg backup: #!/bin/bash PG_USER=donato DATABASE=mydb SERVER=216.58.219.174 DIR="$HOME/pg_bak" DATE=$(date +"%m_%d_%y") FILE="$DATABASE_$DATE" ERROR_FILE="$...
1
vote
0answers
24 views

Read a log file to extract various fields and count the occurance [closed]

I have a logger file like this: 2016-06-11 07:34:01.542 98459 [Thread-23-Job-parser-bolt] INFO JobLoader c.t.commerce.common.utils.APIUtils - Enrichment data updated successful for partnumber : ...
-5
votes
3answers
72 views

How to write a Shell Script that will count the occurrences of each number in a file?

This question was asked by the interviewer today. Suppose there is a file named "Myfile.txt" and it's contains are as below:(not necessarily in one line) 1 3 4 4 1 5 1 9 8 3 2 1 6 0 0 3 4 5 7 8 9 I ...
1
vote
1answer
34 views

Convert GPS coordinates with bash script

I need to convert to a specific format some gps coordinates which are the output of the exif information of a picture. This is the typical output: exif:GPSLatitude: 10/1, 10/1, 10/1 exif:...
7
votes
4answers
179 views

Simplest standard way to print last bash command with timestamp

I would like to print last bash command with its timestamp. history 1 shows the history command itself. I need to use it on many machines, so it should not depend on any custom configuration. There ...
0
votes
2answers
77 views

how to exclude string that include space by “grep -v” [closed]

I have a script that runs by using bash -c and I want to know how many process are running with that script. $ ps ax | grep my_script_run | grep -v grep | grep -v "bash -c" 11121 ? S 0:00 ...
1
vote
2answers
54 views

Bad substitution trying to rename extension [duplicate]

I'm trying to convert all wav and mp3 files to ogg files recursively with find and FFmpeg. I have made the following bash script to do so: #!/usr/bin/env bash # Converts samples to ogg find samples ...
-1
votes
1answer
44 views

What is the error in this script?

I'm getting this error: 1 /home/nacion/mcparley/VentaParley.sh: line 163: unexpected EOF while looking for matching `"' /home/nacion/mcparley/VentaParley.sh: line 166: syntax error: unexpected end of ...
1
vote
2answers
32 views

bash: --argument vs -arg [duplicate]

In most scripts (but mainly bash) it's commonplace to see some arguments that are configured like so: bash-4.3:$ command --longer-argument -la Where did this originate from? I'm mainly just curious ...
0
votes
1answer
40 views

Regex in case statement [duplicate]

I'm having a hard time getting regex matches to work in a bash case statement. Example code: #!/bin/bash str=' word1 word2' echo "With grep:" echo "$str" |grep '^\s*\&...
2
votes
3answers
129 views

Why can I switch to a user but not run a script as it

If I try to switch to a user using command sudo su - kshitiz. It works fine and switches without asking for a password. But if I try to run a script as that user it asks me for a password. sudo -u ...
0
votes
1answer
22 views

What \u001B]0;kuba@jcubic: ~\u0007 escape code do?

When using shell in a box this is returned from the server \r\n\u001B]0;kuba@jcubic:~\u0007\u001B[01;32mkuba@jcubic\u001B[00m:\u001B[01;34m~\u001B[00m$ what ESC]0; and \u0007 do?
1
vote
1answer
17 views

Caller-aware function in bash

I have a function (=callee) that should effectively declare and assign a couple of variables in its caller. It should also be able to tell what it's caller's name is. For now I achieve the former by ...
9
votes
4answers
931 views

Why does cut fail with bash and not zsh?

I create a file with tab-delimited fields. echo foo$'\t'bar$'\t'baz$'\n'foo$'\t'bar$'\t'baz > input I have the following script named zsh.sh #!/usr/bin/env zsh while read line; do <<&...
1
vote
1answer
30 views

Syntax error when exectuting bash shell script from busybox

Syntax error when executing a bash shell script from busybox Script #!/bin/bash for dev in `cat /proc/partitions | awk '{print $4}'`; do if cmp -s <(head -c 2 /dev/$dev) <(echo -n -e '\x38\x6e'...
0
votes
3answers
78 views

Bash array values like variables inside loop

Im trying double loop using array values like array names for loop array1="name1 name2" name1="one two" name2="red blue" for name in $array1 do for value in $name do echo "$name - $value" ...
1
vote
1answer
33 views

How to batch rename files by exchanging substrings in the filenames?

I have files like ABC_asd_f.txt, DEF_qwe_r.txt, ... How can I exchange the uppercases before the first underscore with the lowercases after? So ABC_asd_f.txt becomes asd_f_ABC.txt, DEF_qwe_r.txt ...
1
vote
1answer
32 views

using a bash script to run an interactive program

this is day one for me for bash. perhaps this question has already been asked, but i've tried google and have come up empty. maybe because i don't know how to articulate my question. i have a ...
3
votes
2answers
35 views

bash: loop through two string variables to create symbolic links

I have managed to create two bash variables, both of which are lines of strings. $oldfilenames which looks like path/old-filename-1.txt path/old-filename-2.txt path/old-filename-3.txt path/old-...
2
votes
3answers
67 views

Why is my elif being treated as an else statement in my bash script?

I'm building a bash script that uses wget to GET information from a server using a REST api. I'm using getopts to parse options given to the script and then using an if statement to redirect the ...
3
votes
3answers
90 views

How to do a loop to process two input files

I am using awk to do match two files and then multiply the elements of file2 and file1. awk 'NR == FNR{a[$1]=$2; b[$1]=$3; next} /:/ || !NF{print; next} {print $1, $2*a[$1], $2*b[$1]}' ...
1
vote
3answers
151 views

Use regex to check if particular directory has folders starting with specific word

I am writing a script that checks a certain directory for any sub-directories starting with a specific word. Here is my script thus far: #!/bin/bash function checkDirectory() { themeDirectory="/...
0
votes
2answers
149 views

What is the best practice between using ${var} or $var? [duplicate]

I know that ${var} and $var does the same thing. I also know that you can use brace for advanced options like ${var:=word} or ${var#pattern}. It's also explained here. But I see in some bash scripts ...
1
vote
0answers
29 views

Pipe long running process to clipboard on mac

I have a seemingly long running process (the lg cli debugger) and when I run it it prints out a uri to access the spawned debugger. I'd like to pipe this to my clipboard (pbcopy on mac) so I don't ...
0
votes
1answer
41 views

List files before a specific date in bash [closed]

How to list files before a specific date in bash?
2
votes
1answer
30 views

Cannot stop bash to expand star (wildcard character) passed to app from shellscript

I have a shell bash script wich should pass the star ["*"] wildcard character to an application without using quotation marks. I am reading since hours and always find to use "set -f" inside the ...
0
votes
1answer
38 views

Using a username starting “##” at a bash prompt

Some clown made me a sftp username that started with ##. Now I don't know if the command is wrong or the ftp server isn't responding for certain. Could someone please confirm for me that this should ...
4
votes
1answer
99 views

How can I test if a particular alias is defined?

I have a bash script that needs to behave differently if a particular alias is defined. Is there a way to test if a particular command is an alias in bash?
1
vote
1answer
47 views

How would I make this script more efficient? [closed]

I am writing a script that will systematically install Numix theme using gnome-tweak-tool. I want to make sure that I don't reinstall items if they are already installed, so I used which [name of ...
3
votes
1answer
26 views

removing duplicates from pushd/popd paths

Context linux bash pushd/popd/dirs Problem The problem scenario is very similar to the one stated in this question: removing or clearing stack of popd/pushd paths ... however the goal is not to ...
1
vote
1answer
29 views

How to stop bash being too smart restricting completion options?

I often come across bash getting in my way when I'm doing something like this: cmake -DCMAKE_INSTALL_PREFIX=/usr/<TAB><TAB> Apparently, bash doesn't see that cmake can accept paths and ...
1
vote
2answers
69 views

Rename all spaces in image file names inside html php files

Inside different htm.gz, html.gz and php.gz web files I have images and the ones in .jpg format have name with space instead of "-", but in /images/ directory where all images are located they have "-"...
1
vote
2answers
29 views

Silent stat to check file existence

I'm running a command if a file is present in one line of bash. Here is what I'm doing for now: $ stat /last_dump.sql && mysql -D my_database < last_dump.sql Is it the right way to do ? ...