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

2
votes
1answer
23 views

Error exit script from within command substitution

If I have a function: myfunction() { [ -d somedirectory ] && [ "some other condition" ] || { echo "error" >&2 ; exit 1; } global_var=somevalue } And I call it from within another ...
0
votes
0answers
18 views

how to interpolate a string in this CURL call

In Bash, I have this curl call: curl -d 'user[email]=jj@jk.com&user[password]=abc123' http://domain.com/arc/v1/api/users and would like to interpolate a UNIX timestamp call to add the current ...
0
votes
1answer
38 views

opening multiple tabs in firefox using a one-liner bash script [duplicate]

I am on CentOS 6.6. I have a program that runs analysis and outputs its data in html files. The file structure is dir1/dir1.html dir2/dir2.html dir3/dir3.html I want to open all three html files ...
0
votes
1answer
31 views

What are conditions I can check for detecting error in downloading using bash?

I want to continuously download a link until it successfully downloads, #!/bin/bash while [ some_condition ]; do curl my_url # or vagrant add my_vagrant_url ...
0
votes
0answers
13 views

How to generate total size of files from each unique source in bash

I have a large number of directories which each contain files with the format unimportant_data_here_source_date.gz I want to calculate how much data came from each source. That means figuring out ...
1
vote
0answers
35 views

Bold and Underline using echo with email

I am using a script that emails me a particular status report. The script sends me the contents of several files. I am using echo to provide a heading in the email that is used to differentiate ...
-2
votes
1answer
30 views

Add one text to multiple files using bash [closed]

I have many files with the extension .com , so the files are named 001.com, 002.com , 003.com , and so on. And I have another file called headname which contain the following information: abc=chd ...
2
votes
1answer
73 views

How to get filenames when using find and sed

I am writing a script to apply sed on certain files and then list files that have been changed so that I know which have been modified. This is how I am finding and then using sed: find . -type f -a ...
0
votes
1answer
38 views

Compare a certain lines from multiple documents

I want to compare a certain lines in a multiple documents. I tried using diff and comm, but the conditions are these, the documents are in a different working directory/folder, I could use a ...
1
vote
1answer
44 views

Bash - Running a bash script from within a ksh script

I am on RHEL 6.7 and have a korn shell script that does check pre-reqs, prepares the system for rpm install's (creating directories if they are not already that are required by the product), stops ...
1
vote
1answer
25 views

grep restart script if not running

Hi guys i'm running into an issue here that I need to have a nohup php script run in the background and make sure it's always running and restarted if it crashes. I run the following bash script using ...
-1
votes
2answers
37 views

ssh linux to mac inside and outside lan

Hi this is my first post and I was wondering if anyone can help me? I have ubuntu on my home pc and I want to be able to ssh to a macbook. When they are both on the same wifi network it's no problem, ...
3
votes
2answers
45 views

How to write a “compose” function of bash pipelines with named pipes

This page details psuedocode for creating a compose function that takes n commands and executes them in a pipeline: We program a command compose such that compose cmd1 cmd2 ... cmdn behaves ...
4
votes
1answer
66 views

Why is subshell created by background control operator (&) not displayed under pstree

I understand that when I run exit it terminates my current shell because exit command run in the same shell. I also understand that when I run exit & then original shell will not terminate because ...
0
votes
1answer
30 views

Can someone please explain this error I'm getting in my script

I'm trying to create a script which I can set as a cron job which adds all my dotfiles to a folder I've set up as a github repo then push them every evening. My script is the following. cp ...
0
votes
1answer
49 views

Using sed on files with certain extension inside shell script

I am trying to use sed to find files with certain extension and then replace occurrences of a certain string with another. No directory mentioned using current directory *.h sed: can't read *.h: No ...
0
votes
1answer
40 views

Check how a script was started

I'm making myself a few "helper" scripts, and the first one is to install NodeJS. The first issue I've just solved, was getting source ~/.profile to persist changes. I found out running . ...
1
vote
0answers
51 views

File exists but errors with “mv: cannot stat: No such file or directory”

For some reason my script cannot copy or move files that exist. It comes up with the errors below. Can someone tell me why? cp: cannot stat '/mnt/sd/bbu/install/scratch/bin/.': No such file or ...
2
votes
4answers
52 views

Change dir from script without a “shell procedure” or “sourcing the script”

I know what I can make a shell procedure or source the script instead of running it to cd the shell I am using. What I want to know is there any way to cd the "parent shell" (not sure if that is the ...
0
votes
1answer
53 views

ssh authentication and remote command output's redirection

I need to run a remote capture on a host via ssh and to authenticate twice, but the second prompt is being redirected. ssh -t user@host "sudo tcpdump -s 0 -n -w - -U -i eth0 not port 22" > ...
0
votes
0answers
19 views

Direct stout & stderr to custom log file using logger

Im trying to output stout & stderr of a script to a custom log file while still displaying it in the console as well. I've looked at examples which use tee as well, but would like to have the ...
3
votes
1answer
67 views

Bulk downloading PDFs

This may/may not be possible using bash happy for a suggestion in Python if there is one. But I would like to download all the PDFs/ePubs from the following link https://mises.org/library/books ...
1
vote
1answer
59 views

Infinite loop in bash

I've 672 files in local directory, filenames are like: boutique-*_20160116hh0000.csv, general-tgbt_1_20160116hh0000.csv, where hh - hours' number and (for instance, boutique-a13_15_20160116060000.csv, ...
6
votes
3answers
1k views

Executing mail command from inside a function causes a “fork bomb”

When I try to execute mail from inside a function in a bash script it creates something similar to a fork bomb. To clarify, this creates the issue: #!/bin/bash mail() { echo "Free of oxens" | ...
0
votes
1answer
37 views

How can I get many addresses from many trajectories with bash script without error?

I have many trajectories data. 500k. I try to get adresses of these coordinates. I use bash command in linux. #!/bin/bash filename="$1" while read -r line do uid=$(echo $line | cut -f1 -d,) ...
0
votes
0answers
17 views

Save history to separate file with time-stamp and who did the action

I'm looking for a solution to capture all Linux commands to some file, there are many solutions but I prefer to capture all History to some file. I want it to include : "time-stamp" "Server-name" ...
1
vote
2answers
30 views

How does bash print to the screen if not with a framebuffer? [duplicate]

I noticed that a framebuffer doesn't always exist on some systems. In these cases, how does bash print to the screen (assuming it ever uses fb devices at all)? Since there's no framebuffer device, ...
3
votes
7answers
321 views

Check if shell variable contains an absolute path

I want to check if a shell variable contains an absolute path. I don't care if the path exists or not—if it doesn't I'm going to create it—but I do want to ensure that I'm dealing with an absolute ...
3
votes
5answers
176 views

Command line method to find repeat-word typos, with line numbers

Updated: Clarify line number requirement, some verbosity reductions From the command line, is there a way to: check a file of English text to find repeat-word typos, along with line numbers where ...
4
votes
1answer
469 views

What the devil is overriding my path on SSH login?

I have a server running a Gogs instance (a self-hosted github clone). I recently did a manual upgrade, and moved a bunch of things around, including changing the username that the remote users log ...
3
votes
1answer
53 views

sigint not being propagated to background child process

I need to send SIGINT to terminate a process gracefully but I can't. This is a sample, because the environment in which the execution occurs is 'unknown' (a bash script in travis.com) I managed to ...
0
votes
0answers
27 views

Is “<command> &” same as demonizing a process in Linux? [duplicate]

We all know that any command succeeded by ampersand (&) makes it run in the background. Can we use it instead of demonizing tools? For example: In order to run nodejs server, we use use packages ...
1
vote
1answer
19 views

Workaround for missing rm -I option on OSX? [duplicate]

I'd like to do this, on OSX: alias rm="rm -I" In GNU rm, this means that rm will prompt if it's recursive or if it's deleting three or more files, but not if it's just deleting one or two files. ...
-1
votes
1answer
30 views

Infinite loop one liner for pen testing

A bunch of years back I found this one line of bash script that basically would overload a linux system. All I can remember is that it looked something like this and had the pipe (_(:;){:()|:()}); ...
13
votes
4answers
2k views

What does “esac” mean at the end of a bash case statement? Is it required?

This may be a stupid question but I'm fairly new to bash scripting and have found multiple examples of "esac" appearing at the end of a bash case statement but I have not found any clear documentation ...
1
vote
3answers
123 views

Read a file line by line and if condition is met continue reading till next condition

I have a file foo.txt test qwe asd xca asdfarrf sxcad asdfa sdca dac dacqa ea sdcv asgfa sdcv ewq qwe a df fa vas fg fasdf eqw qwe aefawasd adfae asdfwe asdf era fbn tsgnjd nuydid hyhnydf gby asfga ...
1
vote
2answers
32 views

Extract a particular substring from filename

I am quite novice in bash scripting. The task I need to solve is extract a particular substring from each filename in a directory. Example file names: Bob Marley - I Shot The Sheriff-2XiYUYcpsT4.mp3 ...
1
vote
2answers
50 views

Backtick command encapsulation

test@debian:~$ echo `echo \`echo "uh!"\`` uh! How does the Bash do that? It seems that it first executes the expression in the non-escaped backticks, which gives back (the double-quotes "" are ...
0
votes
1answer
32 views

colored bash does not work as root user

I have noticed that when I ssh to a server and then su to the root user, I do not get color in bash. In this specific case when I say "do not get color in bash" I am talking about editing files with ...
1
vote
3answers
85 views

ssh change user and execute command

This is my command that I have in my script: ssh -i $KEY $USER@$HOST "sudo su tom; echo $DATA >> /home/user/file.txt These commands work fine on there own but together in the script it just ...
2
votes
2answers
40 views

Autocomplete from grep output

How might I more easily use a filename found by grep as an argument to vim: $ grep -r foo * lib/beatles/john.c lib/pantera/phil.c lib/pinkfloyd/roger.c lib/pinkfloyd/richard.c ...
0
votes
0answers
9 views

Export variable failed when I was compiling NETCDF

I'm compiling NETCDF on Linux. After configure, make,make install, I have already install NETCDF on /disk3/lly/lib/netcdf-4.1.3. Then, using vim ~/.bashrc,edit: export ...
10
votes
2answers
997 views

Is the “$?” (dollar-question mark) variable available only in the Bash shell?

In the Bash shell, I can get the command exit status through the $? variable: # ps -ef | grep "haha" root 15439 15345 0 23:02 pts/0 00:00:00 grep --color=auto haha # echo $? 0 Is it ...
0
votes
1answer
37 views

Identifying duplicate fields and REMOVE both with awk

Previously, I asked the question: Identifying duplicate fields and print both with awk. I have a file with multiple columns and wanted to identify lines where specific column values (cols 3-6) had ...
1
vote
2answers
47 views

How to execute a command randomly over a given time interval?

I am interested in a running a Unix command once randomly over a given time interval. For example, if the command is ls and my time interval is between noon and 2pm, how could I start a background ...
3
votes
2answers
33 views

Why builtin times doesn't work in pipeline?

I've the following sample script: #!/usr/bin/env bash sleep 5 printf "times cmd: " times printf "pipeline: " times | ( read user sys; echo $user; ) printf "head: " times | head -n1 printf "times cmd ...
1
vote
0answers
17 views

limit inotifywait output to n/sec

I have this inotifywait command watching a log file, once triggered runs some other code which takes 0.2s to complete. This works fine when the log is not being massively updated, but when there's ...
0
votes
2answers
32 views

split string at first occurrence of a delimiter

I do a grep in a shell (bash) to search for some ids in many log files: grep "100200300" my.log* result is something like that: my.log:Jan 17 15:04:52 100200300 ok my.log.1:Jan 17 14:35:17 ...
7
votes
2answers
142 views

Redirecting standard error output to bash variable

Here's a C code snippet that will cause segfault: // segfault.c #include <string.h> int main() { memset((char *)0x0, 1, 100); return 1; } Compile it with: gcc segfault.c -o ...
0
votes
1answer
24 views

Sort words from n rows

i need to print all the unique words and their occurences from first n rows in a give file. I have to sorted by their number of occurences and then alphabetically.(the only separator is " ") ex: for ...