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

-1
votes
2answers
34 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
48 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
50 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
51 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
52 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
66 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
36 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
16 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
319 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
158 views

Command line method to find repeated word typos in English text

Updated: Added third, multi-line sample to test solutions with From the command line, is there a way to check a file of English text and find repeat-word typos, in order to help correct them? To ...
4
votes
1answer
467 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
52 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
118 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
83 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
39 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
989 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
140 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
23 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 ...
0
votes
2answers
19 views

In xterm(mintty,bash), how can I open a file in the exist vim process?

I used to open file in multiple tab like visual studio or eclipse do. How can I open the a file into the exist vim process ?
-3
votes
7answers
107 views

Is there a way to prevent sed from interpreting the replacement string? [closed]

If you want to replace a keyword with a string using sed, sed tries hard to interpret your replacement string. If the replacement string happens to have characters that sed considers special, like a ...
0
votes
0answers
33 views

Updating/compile sendmail script not working.

I have wrote a script to update sendmail and compile on unix system I put those lines if [ ! -e $CWD/src/$NAME-$VERSION.tar.gz.sig ] then echo "$NAME-$VERSION signatures missing" wget -c ...
1
vote
1answer
31 views

How to write bash script in Makefile

I have a directory structure like this: `-- dev |-- example-object | |-- example-object.tex | `-- example-template | |-- example-template.tex | `-- instances | ...
3
votes
1answer
83 views

List of VBox Machines Help?

So, I'm writing up a bash script to list out the VM's on my host, so I can make sure they are fired up when the host machine restarts... no problem here... my issue is getting the list of the ...
3
votes
3answers
233 views

Replace a string in a string with a new line (\n) in Bash

I tried this command: [silas@mars 11]$ string=xyababcdabababefab [silas@mars 11]$ echo ${string/abab/"\n"} xy\ncdabababefab [silas@mars 11]$ I also tried to replace "\n" to '\n' and to \n . I can't ...
3
votes
2answers
85 views

Handling duplicate programs names bash

I'm wondering if $PATH cascades entries. You'll all need to take a leap of faith with me here, but here it goes. Let's say we have a Java executable at /usr/bin/java but this version is very old and ...
2
votes
4answers
94 views

Moving and renaming hundreds of .jpg files, all named 5003.jpg

So here's the deal, my girlfriend wants me to transfer all of her photos off from her iPhone onto her laptop (on which we are running Ubuntu 14.04). All of the dedicated programs I tried to do this ...
1
vote
0answers
18 views

Real-time monitoring of changes in swap use (per process)

I'm looking for a way to observe which processes in my system are consuming an increasing amount of swap over time. The following function generates a list of swap user per process : sbp(){ grep ...
1
vote
1answer
46 views

Exporting Variables and setting Global Variables in Bash [closed]

My objective is to create a list of variables that can be called or referenced by any test script that is being executed. There are a lot of test scripts on the system but the variables are ...
1
vote
2answers
20 views

linux bash if statement inside for loop [duplicate]

I am attempting to iterate through 1-30, say hello #number for each except for number 10. This is what I have which is not working for i in {1..30}; do if [i != 10]; then echo "hello $i"; fi; done ...