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.
2
votes
1answer
23 views
pipe data into process that's already started
Say I start a node.js process like so:
node script.js &
is there a way to pipe data into that process after it has started?
normally, we do this:
cat <file> | node script.js
but the ...
-2
votes
0answers
17 views
Continuous For Loop bash
I am still quite a noob at bash scripting, and I need to run the following 16 times, with each iteration changing specific octets on the IP address:
for i in `cat file | sed -e 's/192.168.3.13/192....
1
vote
2answers
26 views
Here-document without interpreting escape sequences, but with interpolation
Is there any way to cat a file without interpreting the double backslash as an escape sequence?
In this example a tex file is created:
cat <<EOF > file.tex
\\documentclass[varwidth=true,...
1
vote
1answer
15 views
Get reference to stdin file descriptor of Node.js process, must work on MacOS too
On a Linux machine, if I have the pid of a process, I can write to the stdin of that process using something like:
/proc/<pid>/fd/0
but on MacOS, this doesn't appear possible. I am told that I ...
2
votes
4answers
123 views
open any .c file with sublime text using terminal command
The IDE that I use is Sublime Text 3
If I want to open a file through terminal with sublime text, I have to type:
subl <file>.c
I want to edit my .bashrc so that any .c file automatically ...
-9
votes
0answers
22 views
backup the file / directory [on hold]
Write a shell script that consists of a function that take backup either file or directory and it accepts the file/directory name as an argument. Name this function "backup" and call it in your script....
2
votes
0answers
25 views
Send EOF to named pipe - cleaning up / drying up fifo
If I have some random processes reading from a named pipe:
tail -f MYNAMEDPIPED
cat MYNAMEDPIPE | someOtherProc
Elsewhere, I have a handle on MYNAMEDPIPED by name.
is there a safe and clean way to ...
-1
votes
3answers
24 views
Conversion of specifc time to milliseconds using AWK
I have a file with data:
[15:29:58.496640]
[15:29:58.496644]
[15:29:58.496665]
[15:29:58.496682]
[15:29:58.497096]
[15:29:58.498621]
I want the output in milliseconds using awk on CentOS.
For ...
1
vote
2answers
20 views
Reading length of piped value?
How can I check the length of a piped input? I'm trying:
echo "A" | xargs sh -c 'echo ${#$1}'
Also:
echo "A" | xargs sh -c 'echo ${#\"$1\"}'
Based on the answers here, for a non-pipe example.
0
votes
0answers
31 views
find command not working when assigned to a variable [duplicate]
I want to get the list of all the files in a directory
WRKDIR=/home/kumar/datafolder
FILES=find "${WRKDIR}" -type f
for f in $FILES
do
echo "Processing $f file..."
done
/home/kumar/datafolder: ...
0
votes
2answers
32 views
Read stdout/stderr from subshell to parent
In a shell script, I want to write to the stdin of an external process X using a named pipe, and I want to send the stdout/stderr from another named pipe to the current terminal.
The external process ...
0
votes
3answers
45 views
How can I echo an output of a command that returns nothing/null?
I would like to echo something from an output of a command that returns nothing.
This is the content of fnames.txt
company_TOYOTA_666_696969696*
company_FORD_123_435345666*
...
0
votes
1answer
41 views
Is there a Vim like “Command Line Window” for Bash?
Is there something similar to Vim's "Command Line Window" for Bash where I can see/edit/execute items from the history?
In Vim when I press : and then Ctrl-F it opens the window that shows the entire ...
1
vote
1answer
34 views
Accessing results of pipe as variable?
I want to access the results of the last pipe command from current pipe command. For example:
echo "0x1a" | perl -le 'print hex("$RESULT_FROM_PIPE");'
What is the proper syntax for this?
0
votes
2answers
24 views
command to capture current command prompt text
I'm using https://github.com/magicmonty/bash-git-prompt to customize my bash prompt. so, my prompt usually looks something like this
✔ ~/dotfiles [master|⚑ 1]
15:00 $
is there any command with which ...
0
votes
1answer
20 views
Help with right column alignment.
I have this script written.
#!/bin/bash
clear
echo -e "---------------------------------------------------------------------"
echo -e "| Client Name | No. of Backups | Size | Is Partial | ...
2
votes
1answer
29 views
How can I create an additional lo interface?
I'm trying to listen to two different interfaces that are loopbacks on a single Linux machine using wireshark.
I've seen a method to add different loopback interfaces here, but that doesn't actually ...
0
votes
2answers
37 views
Why is /dev/stderr invalid when redirecting to a pipe?
I recently stumbled over a surprising issue with an invalid /dev/stderr on an up-to-date cygwin which is also present on a well-matured Debian installation.
Background: I'm using tools which produce ...
0
votes
1answer
33 views
What does parent process -bash mean?
I have a process, x, which has the PPID (listed by ps) or the process -bash started about a month ago..
myuser+ 11861 11858 0 Jun13 pts/178 00:00:00 -bash
myuser+ 16321 11861 8 Jun13 pts/178 2-01:...
0
votes
2answers
37 views
Bash - get string containing spaces in for loop [duplicate]
I am attempting to write a bash script that operates on each directory in a subset.
Unfortunately the path contains spaces, and I am unable to change the name.
The for loop insists on breaking at ...
1
vote
1answer
30 views
GNU Parallel to process multiple files in parallel in Unix with bash
I have a bash script I am using to iterate over a list of files and search for regex matches. Here is a snippet from my current code:
for file in $Files_To_Parse; do
(cat $file) | grep -ioE "($...
0
votes
1answer
29 views
understand the order of operations for bash parameter expansion
I read a similar example from bash programming book:
$ cat indirection
#!/usr/bin/env bash
set -x
num=1
eval "${!num#*:}"
$
When I execute the script with bash indirection "test:echo blah", then ...
1
vote
2answers
30 views
Bash wilcard expansion with command-line switch
I am using a command that takes input of the form
command [-a input_files]*
So I can call command -a foo or command -a foo -a bar -a baz.
Now, I am trying to automate a workflow and would like to ...
-1
votes
1answer
18 views
How to do this with while loop [duplicate]
Problem is:
grep the output of ps aux for any instance of firefox, if firefox is already running, open link in new tab, if firefox is not running, start firefox and open the link.
Point to be noted ...
0
votes
1answer
13 views
Gather custom commands in a single directory
In a Django project, we are several persons using the same custom bash commands. In the project directory, there are too much of those custom commands. You could see those files in green in the ...
0
votes
3answers
20 views
Is it possible to define directory-sensitive aliases in zsh (or any other shell)?
I want to use different aliases (or perhaps: the same alias differently) depending on the current working directory. For example, I might want to use l as a shorthand for ls with some extra options. ...
0
votes
2answers
29 views
Houskeep old files and dirs
I'm having a bit of trouble, I'm trying to do a script that will create a list of files and dirs older than 7 days and delete the ones that are not in the list tokeep.list.
My first problem is that if ...
0
votes
0answers
14 views
avoid username/password being caught by ps [on hold]
I have this code in my script:
query=`/some_dir/bin/sqlplus -s <<-eof $username/$password
#some query here
eof`
Now, when this command is executed, a ps command may reveal the ...
1
vote
3answers
49 views
How to execute a find command using a set of strings from a line in a text file
This is the content of my text file named fnames.txt:
"SAMPLE_NIKE_856_20170703*"
"SAMPLE_ADIDAS_856_20170702*"
"SAMPLE_ANTA_856_20170630*"
"SAMPLE_JORDAN_856_20170627*"
"SAMPLE_CONVERSE_856_20170229*...
0
votes
0answers
11 views
exiting netcat when an specific line received
I'm trying to create a bash script to communicate with telegram-cli which is listening on a local port
I'm connecting to it like this to be able to receive response of my command (which can take ...
0
votes
2answers
23 views
Shell script to copy list of files with spaces [duplicate]
I am trying to create a small script that takes a filename, in which the absolute location of files are listed, and to copy it to some other location.
Content of the file test.txt for example:
/...
2
votes
3answers
44 views
Bash - move files into numbered folders oneliner
I can create multiple numbered folders at once like so:
mkdir Season\ {1,2,3,4,5}
Is there a way I can run the following commands in a oneliner (without a for loop):
mv 01.* Season\ 1
mv 02.* ...
-1
votes
1answer
41 views
Stop array strings being split on white space [on hold]
I have an array which is output from jq. However the array is being split on the space between the characters.
How can I read the strings into an array without the elements being split on white space?...
2
votes
5answers
265 views
Append at the end of line using sed
I have already seen other answers trying to solve my problem but I am not able to solve it.
#!/bin/bash
s=org.gnome.Terminal.Legacy.Keybindings
g=$(echo $s | sed "s|\.|/|g")
echo $g
I have above ...
4
votes
2answers
50 views
Add BASHPID to history?
I often have multiple sessions running at any given time. This sometimes leads to issues when trying to reconstruct work using history. As a result, I was thinking it would be useful to include the $...
-1
votes
1answer
39 views
Issue reading from csv [on hold]
I'm attempting to read from a csv file in a bash script and so far am unable to get it to work.
CSV File
col1,col2
fakenode1,1.1.1.1
fakenode2,1.1.1.2
fakenode3,1.1.1.3
fakenode4,1.1.1.4
fakenode5,1....
0
votes
1answer
24 views
Send data to a command using an specific frequency
I want to do a bash script that reads a file that each line contains a timestamp and a value, and send the line to another command with the same frequency as the data.
For example, if I have these ...
-4
votes
3answers
40 views
Extract Complex String Inside Parentheses in Linux Bash
I want to extract the string like below via the Linux bash tools:
XXAAGGHH (XXXXX) ERRTYTUUUI
AAAAAAAA ( %%))XX) $@@$&%^&&
AADDDDD$ (.SD F@* @) *$%^^&^&&&
AA^@%%^^ ()[))DS(...
0
votes
0answers
6 views
Permission denied with cgroup [duplicate]
I'm new with cgroups and got stuck with adding process in specific cgroup. This what I did so far:
I created a directory in sys/fs/cgroup/memory/ with mkdir mycgroup, I want limit the memory and I did ...
0
votes
0answers
17 views
Move folder contents based on group match after new folder is created as in group [on hold]
I need to do the following and below is the code i used, pls help to enhance it to 'correctness'.
Read the file content & create folders G1, G2 in dst dir.
Move F19,F20 folder contents to above ...
-2
votes
0answers
37 views
Create word from combination of groups [on hold]
I have password to decrypt example:
(1)(2)(3)(4)(5)sada(6)(7)
(1) - group of letters: d,s,a
(2) - group of special letters: ",$,^
(3) - group of word: asdas,asdasda,asdfew,
etc.
and there is more ...
-3
votes
2answers
50 views
How do I add line numbers to text? [on hold]
My text is:
Hi
Bye
Nope
Sorry
Cya
Chill
How can I make it:
[1] Hi
[2] Bye
[3] Nope
and so on and so forth?
1
vote
6answers
63 views
How can I run a program from bash ignoring its stdout so i can run more programs? [on hold]
I'm trying to do is create a new process, from within bash, like nothing ever happened, except my terminal is on the next line, where that process would normally steal my stdout...
Let's say I want ...
0
votes
1answer
16 views
How to display three whiptail on the same screen?
I have three very long processes that I need to monitor. Rather than having three terminal windows open each with a separate whiptail progress bar. I am searching for a way to send three whiptail ...
1
vote
2answers
38 views
How to Loop through multiple subdirectories to find files using bash [on hold]
I need to loop through multiple subdirectories to find fastq files.
fastq files are in /path/sample/a/b/c/.fastq
currently I use this:
${inputDir}/**/**/**/*.fastq
My inputdir will be only: /path/...
0
votes
3answers
50 views
Purpose of '&& bash' in a command (not the '&&' part, the 'bash' part)
I just saw the list of commands below on a web page - they install a static version of ffmpeg in the user's ~/bin directory. The commands are not part of a script, the user is supposed to copy and ...
1
vote
1answer
26 views
bash + regular expression + validate machine name [on hold]
How to match the following hostnames with a bash regular expression?
My Linux hostnames are: star01 , star02 , star03 , start04.
My goal is to validate the string "start0" with any second number
...
1
vote
2answers
46 views
Using subshell to pass parameters with spaces
I have a shell called "name_value.sh" that I want to pass parameters generated in a sub-shell. How can I ensure the command receiving parameters from the sub shell retain spaces?
NOTE: This is an ...
0
votes
1answer
18 views
Yad forking and return results
I'm trying to make a yad process collaborate with another (a mounter but that's not very important).
I have a code structure like this (simplified) in the critical part:
`
yad --list --button=gtk-...
0
votes
2answers
36 views
How to source .bashrc file directly after I close and save?
For example, I have a function in my .bashrc file:
function open_bashrc() {
gedit ~/.bashrc
source ~/.bashrc
}
So anywhere I am, if I type open_bashrc, then it will open the .bashrc file. I ...