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

13
votes
2answers
42k views

sudo as another user with their environment

$ whoami admin $ sudo -S -u otheruser whoami otheruser $ sudo -S -u otheruser /bin/bash -l -c 'echo $HOME' /home/admin Why isn't $HOME being set to /home/otheruser even though bash is invoked as a ...
1
vote
2answers
72 views

Perl stripping substring with $ in front

I get that perl thinks the part of the string with $ are perl variables. What I'm trying to do with the perl call, is redefine variables preceded by a $ as \$, but that's throwing other errors. I ...
6
votes
2answers
116 views

Notification Listener Behaving Strangely when Backgrounded

I've been struggling to get my IRC-Bouncer/Notification Script working. This is meant to be a script which will automatically login to a remote machine, attach to a screen session (or start one if ...
1
vote
2answers
6k views

how do I run a cron job with a specific user?

My cron and scripting skills are very poor, but I need to run a job every 5 minutes by user 'cpc'. So I created a script and left it at /root. My crontab -e entry about it is: 0-59/5 * * * * /root/...
1
vote
2answers
46 views

Specifying comma-separated command line parameters based on text file lines

I want to run a command like: command argument --parameter=param1,param2,param3 where param1, param2, param3 may be any number of parameters coming from a file params.txt, each on one line. I can ...
11
votes
4answers
10k views

realpath command not found

I have debian squeeze amd64. My current shell is bash. If I write the following in my terminal, it works: $ uname -a Linux core 2.6.32-5-amd64 #1 SMP Fri May 10 08:43:19 UTC 2013 x86_64 GNU/Linux $ ...
12
votes
1answer
259 views

Setting temporary bash aliases when entering a folder

Sometimes I like to have very customized bash aliases and maybe keybindings when I enter on a folder (can be a project where I'm used to type lots of commands from CLI). Lets suppose when I enter a ...
1
vote
2answers
46 views

sed: Grabbing and replacing all data between last backslash and a comma

I have data in a csv format that looks like this: F1309-042543,07/14/09 01:39:25,N/A,C:\windows\system32\netsh.exe,N/A,True F1309-042543,11/21/10 03:24:02,N/A,C:\Windows\System32\networkexplorer.dll,...
9
votes
1answer
326 views

Resume a suspended process in a for loop

I am running in bash: for i in ull-*.pbm; do convert $i tmp2/$i.pdf ; done I Ctrl-Z in the middle of running, and then fg its job id. But the remaining iterations do not continue to finish. I ...
0
votes
0answers
21 views

Ensure that file socket is already opened

I'd like to open a simple file socket that can run in background like: nc -l -k -m 10 -U my_socket -c cat & so other processes can connect into it with nc -U my_socket -c read. After this ...
34
votes
13answers
3k views

What is a fast command line way to switch between multiple directories for system administration?

What is a fast command line way to switch between multiple directories for system administration? I mean, I can use pushd . and popd to toggle, but what if I want to store multiples and cycle through ...
1
vote
2answers
47 views

Detect pushd depth in bash?

I would like to be able to programmaticly detect when my pushd stack is non-empty, within a bash shell. Is there any way to detect this? Something akin to $SHLVL would be nice. But so far, the only ...
0
votes
1answer
24 views

Bourne to grep and forward specific text from across a LAN

I'd like to develop a shell that keeps forwarding me the greped text(say compilation errors or warnings, in a single txt output) to some E-mail ID or on some NAS mount point, most importantly from ...
-1
votes
1answer
29 views

How to record numbers of array elements based on selection comparision criteria

I have many files which has many 2x2 arrays. In the present example I show only one file (file1) Input file(file1): 1: 6.1703 541.631 46.0391 2: 6.1930 537.446 45.9239 3: 6.1931 177.171 288.579 ...
0
votes
0answers
42 views

Linux + how to shutdown application properly with reboot or init 0 + init.d scripts

I have Linux Redhat (version 6.5) machine that manages some application before each reboot or init 0 I shutdown the application as the follows: /etc/app-LM.bash /etc/app-UPP.pl /bin/DT-apl.c ...
1
vote
0answers
26 views

Grid Engine for program that needs X11 but doesn't require user input

I have a bash script that calls an executable (some commercial software) in "batch mode". On the commandline, if X is available the program runs to completion and then quits, but if not the program ...
9
votes
11answers
10k views

linux diff tools: create list of modified files

How do I create a list of modified files programmatically using linux command line tools? I'm not interested in the difference in any particular file (delta, patch). I just want to have a list of new ...
1
vote
2answers
45 views

print multiple words seperated by space

I have a text file and the data inside has format like (name age country): michael jordans 25 US adam smith 30 UK chris wood ABC 22 Aus if I use command: cat text.txt | awk {'print $1'} --> it ...
1
vote
2answers
46 views

Alias in bashrc - can't get it to work [closed]

I created a shell script and wish to add it to bashrc. I opened /home/jub/bashrc and added the following to the end of the file: alias myfilesync = './/home/jub/Documents/scripts/myfilesync.sh' Then ...
0
votes
1answer
63 views

Curl a string with whitespaces and characters in it? [duplicate]

I'm trying to create a "simple" script that I'm going to use to create some documentation for Unix/Mac machines. I've successfully received the information I need, but it seems like I can't send it ...
0
votes
0answers
40 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 ...
0
votes
3answers
64 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 ...
-1
votes
1answer
38 views

Why is `sudo cat /tmp/1 > file` wrong? [duplicate]

I do sudo cat /tmp/1 > /etc/udev/rules.d/69-libmtp.rules but I get bash: /etc/udev/rules.d/69-libmtp.rules: Permission denied System: Ubuntu 16.04 Linux kernel: 4.6
5
votes
2answers
356 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 ...
36
votes
4answers
22k views

How can I delete a word backward at the command line (bash and zsh)?

How can I delete a word backward at the command line? I'm truly used to some editors deleting the last 'word' using Ctrl+Backspace, and I'd like that functionality at the command line too. I am ...
1
vote
1answer
74 views

Killing bash causes it to respawn itself

I'm SSHed into my computer at home and I'm trying to format a drive. lsof /dev/sdb2 shows: COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME bash 1366 mitch cwd DIR 8,18 24576 ...
15
votes
1answer
758 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 ...
3
votes
2answers
9k views

bash: insert character at specified position in file

Lets say I have following file word1 something blabla anotherword somethingelse asdf yetanother else 123 For each line, I need to put a comment infront of the ...
0
votes
1answer
35 views

Linux Check Image Exists at Apache URL

I'm writing a program that uses a Linux command to check if a file exists on the local server. The program executes a command with a supplied argument ls *ARG_GOES_HERE* &> /dev/null and ...
0
votes
3answers
4k views

The best way to add Unix Shell variables to CURL GET request

Let’s say I use curl –X GET command with the following link: “$WEBSITE_URL/ACTION_NAME/ACTION1;id=$ID?Command=TEST&id1=$ID1&id2=$ID2&id3=$ID3” As you can see, there are some $variables ...
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 ...
1
vote
3answers
2k views

Split XML file into multiple files

I have an xml file that have different nodes, I want to split files like this: <unix> <mm> </unix> <osx> <nn> </osx> When I run the script I want it to make ...
2
votes
4answers
242 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.
25
votes
9answers
21k views

How can I set my default shell to start up tmux

I would like my default bash shell to go straight into tmux instead of my always having to type tmux every time.
2
votes
3answers
130 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 ...
34
votes
3answers
15k views

Terminal prompt not wrapping correctly

I have an issue where if I type in very long commands in bash the terminal will not render what I'm typing correctly. I'd expect that if I had a command like the following: username@someserver ~/...
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 ...
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, "...
-5
votes
3answers
105 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 ...
0
votes
1answer
31 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
3answers
80 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" ...
28
votes
6answers
44k views

How to copy some, but not all files?

So, you can use the * as a wild card for all files when using cp within context of a directory. Is there a way to copy all files except x file?
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
0answers
24 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-...
0
votes
2answers
191 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 ...
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
1k views

Bash to join columns from multiple files

I have around 20 files in different folders for which I have created a separate file called pathtofiles.in which lists path information: /home/users/gray_wolf/unix/File_1.tsv /home/users/gray_wolf/...
-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
132 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 ...
13
votes
4answers
7k views

How to /dev/null background processes “informational” output?

[USER@SERVER ~] sleep 3 & [1] 5232 [USER@SERVER ~] [1]+ Done sleep 3 [USER@SERVER ~] How do I /dev/null these two messages?: [1] 5232 [1]+ Done sleep ...