Questions tagged [bash]

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
2answers
28 views

toggle a program using bash script

I am trying to make a script that will toggle redshift (a night mode application). So, I've done this, #!/bin/bash pgrep redshift > /dev/null && \ killall redshift || \ ...
2
votes
1answer
61 views

How to render variables without quotes in bash script?

The following script: $ cat runme01.sh #!/bin/bash A=myval B=$A/{fix} C=$A/fix set -xT echo $B echo $C prints the following if ran: $ ./runme01.sh + echo 'myval/{fix}' myval/{fix} + echo myval/...
2
votes
2answers
43 views

How to squelch sh errors from imported bash functions?

So I've got a .bash_aliases file with many exported bash functions inside; a good deal of which are incompatible with sh... The problem is that sh is used all over my laptop (OS X) and linux machines ...
0
votes
1answer
42 views

How to redirect a command with parameters in bash?

I want to output "hello" when rpm -qf /etc/redhat-release is typed. Otherwise rpm should work as it would normally.
1
vote
1answer
25 views

Output fdisk bash command to multiline variable

I can't seem to figure out how I can put a fdisk command from a bash script in a multiline variable. Here is my code hdds="$(sudo fdisk -l | grep "Disk /dev/sd" | awk '{print$2}' | sed 's/://g')" ...
3
votes
2answers
61 views

join replaces tabs by spaces

I'm trying to join two csv files, sorted, and with tab delimiter. I'm new to the join command, so I'm not too sure about how to use it, but it seems to be replacing every tab in the files with spaces ...
2
votes
2answers
48 views

Linux Bash: Variable to another variable [duplicate]

i have this: echo $MSG | sed -e $'s/;/\\\n/g' I want to put the result of that sed in a new variable called $MSG2 Something like: $MSG2=echo $MSG|sed -e $'s/;/\\\n/g' How can i do it? Thank you!...
1
vote
1answer
66 views

$! not being set to the PID of a > >(…) process substitution used with an external command

Bash 4.4.19(1)-release I have below a simple script which is the basis for a logging app. For various reasons I had to use process substitution. The runner is the heart of the app and since ...
1
vote
1answer
40 views

Is it possible for a function to distinguish if it is run like this? “${@}”

This is my simplified script. I am wondering if the proc() can know if it is run directly or through the runner. #!/bin/bash runner () { "${@}" } proc() { eval 'version=$(echo "SUCCESS: ****...
0
votes
0answers
30 views

Comparing Timestamps

My users sometimes get alerts with a timestamp, (from another system, via email) but no hostname. I want to give them a function that can compare timestamps in my system that's designed like this: /...
0
votes
2answers
53 views

bash syntax error: invalid arithmetic operator (error token is “.google.com”) when parsing through array

I have an array of domains that I am attempting to iterate through and check if a string from a file matches any of the domains in the array. However, when the for loop starts, I get an error line ...
0
votes
2answers
36 views

I cannot get the PID for this “${@}” 1> >(2log) 2> >(2log2scr | tee >&2)

I searched a bit on how to do this, but I cannot find a solution. I am using process substitution cause of necessity. I want to wait for all the processing to finish before proceeding. How do I get ...
1
vote
2answers
31 views

Tomcat startup script output not available with piping (grep)

I'm completely puzzled by this behavior of Tomcat 9.0.21 startup script catalina.sh: # following line added by me echo "CATALINA_HOME" # following line added by me echo $have_tty if [ $have_tty -eq ...
0
votes
0answers
16 views

remove pattern from string using sed and a variable [duplicate]

I want to remove a pattern from a string (using sed and pipes), but this pattern is not always the same and is defined previously on a variable. this example mimics the desired behavior toremove="...
1
vote
2answers
52 views

Merge duplicate keys in associative array BASH

I've got an array that contains duplicate items, e.g. THE_LIST=( "'item1' 'data1 data2'" "'item1' 'data2 data3'" "'item2' 'data4'" ) Based on the above, I want to create an associative array that ...
0
votes
1answer
47 views

How can a single file system object be both a symlink and a directory?

When I ls it, it's a directory with a bunch of files in it. But when I ls -l it, it's a symlink to something that's NOT a directory. What's going on — how is it possible? $ ls /sys/class/net/...
2
votes
1answer
39 views

Remove carriage return (\r) from variable in expect script

Setup Ubuntu 16.04 expect Scripts In the simple script bellow the goal is to simply find the oldest .zip file in a directory on a remote machine using ssh. Then use scp to download this file to the ...
0
votes
1answer
36 views

Fix the output of uptime

So I've been experimenting with Bash not too long ago, and I want to manipulate the output from the "uptime" command. I managed to change the output of up x minutes to 0:05 for example if the up time ...
0
votes
1answer
58 views

Process Substitution ECHOS undesirable 'shell prompt'. Can I disable it?

NOTE: This question has arisen due to asynchronous processing of 'Process Substitution'. The script responses were deceptive, causing many lost hours. A previously related post is here: cat in process ...
5
votes
0answers
43 views

cat in process substitution hangs: what is it waiting for? [duplicate]

I have this piece of code using Process Substitution. When I run it, it works fine, but it does not exit - just hangs there waiting for input. Why and how to overcome? prepro() { in=$(<...
1
vote
1answer
33 views

Inconsistent behavior of bash string replacement

When I print a variable with one substring replacing another as described in this documentation, it behaves correctly: stringZ='abc - 123' echo $stringZ # abc - 123 echo ${stringZ/ - /...
3
votes
0answers
69 views

What does it mean if a process has an O or an I at the start of the line?

After running ps, I noticed that a couple of the processes had an O at the start of the line. In all my years, I've never seen this. I thought that the meaning of the indicator might be common ...
24
votes
3answers
4k views

How can I detect if I'm in a subshell?

I'm trying to write a function to replace the functionality of the exit builtin to prevent myself from exiting the terminal. I have attempted to use the SHLVL environment variable but it doesn't seem ...
0
votes
1answer
28 views

How to assign a zero-length, non-null string

Based on this, amongst many other things I've read, my understanding is that a='' makes a both null and zero-length. But, then, how does one create a zero-length, non-null string? Or, is there no ...
0
votes
1answer
50 views

How can I upgrade a primitive Netcat shell to a fully-featured login shell with tab-completion and line editing?

How can I upgrade a primitive Netcat shell to a fully-featured login shell with tab-completion and line editing? Suppose I start a remote (reverse) shell using Netcat as follows: nc -lvp $port nc $...
0
votes
2answers
30 views

Bash - here doc read input value from another user

I have a here document inside a bash script. I want to read a value from it like that : su myUser<<SESSION set -x echo -n "Enter your name and press [ENTER]: " read name echo "the name is $...
3
votes
1answer
67 views

Kill the child process in a child xterm but not xterm

I'm new to Linux. I have python scripts in different files, each one performing a desired function. foo1.py foo2.py foo3.py Each one of these scripts should do cleanup before being terminated. ...
3
votes
1answer
48 views

Resume Bash Script After Reboot

I have a bash script that changes some configuration in OS and database and it needs reboot then other commands are needed to be run. something like this: newvalue1= ip= . . some commands . ....
0
votes
1answer
63 views

Can I process command output just before sending it to a file (one liner)?

I have a command processing function that runs its arguments and outputs the results to a file. The outputs of those commands must now be PROCESSED just before going to the file. I have only one ...
-1
votes
0answers
41 views

Bash script that renames log file numbered? [duplicate]

for the filename ending .log.1, rename it to .log.2 for the filename ending .log.2, rename it to .log.3 and so on For example, given the following directory: access.log error.log error.log.1 error....
2
votes
2answers
121 views

Add leading zeroes to a user's input but is being transformed with printf

I am currently looking for an alternative to the following code that works a little less 'wonky'. printf "Please enter the ticket number:\t"; read vTICKET; vTICKET=$(printf %04d "$vTICKET"); printf "$...
1
vote
1answer
39 views

bash set variable to command output

Trying bash shell scripting and running into small issue: # hostname --short 7phdsn01 # virsh --readonly list --state-running --name Nagios # set $(hostname --short)=$(virsh --readonly list --state-...
0
votes
1answer
46 views

Difference between two ways to grep from input file

I have an input file we'll call scan.data. It contains a list of words that I'm going to grep. I've found two different ways of doing this, but I get drastically different results: IFS=$' ' find /...
0
votes
0answers
35 views

Storing a grep outcome into a variable [duplicate]

I've recently begun working with Bash and I was trying to do the following: Format the output of uptime Whenever you input uptime into bash you get something along the lines of: 20:30:54 up 43 min,...
-1
votes
1answer
32 views

Script variable to execute default terminal

How do I open the default terminal emulator in a bash script? For example I want my wine game to launch inside whatever terminal emulator is set as default, hence providing me with a debug interface. ...
21
votes
2answers
2k views

Why are backslashes included in this shell script?

In my copy of the conda.sh script, I see the following lines: if [ -n "${_CE_CONDA}" ] && [ -n "${WINDIR+x}" ]; then SYSP=$(\dirname "${CONDA_EXE}") else SYSP=$(\dirname "${CONDA_EXE}"...
0
votes
2answers
28 views

Finding a file by alphabetical order

Using bash, I need to be able to find a file in a specific position when listed alphabetically. For example, if I had the files a, b, c, d, e in a directory, and I wanted to find the third file, I ...
0
votes
1answer
42 views

File is not sent via ftp - error: “The parameter is incorrect”

This is the bash code: ftp -n <ftpadress> <<EOT <credentials> binary put $pathfile$reportfile $remotepath$reportfile put $pathfile$logfile $remotepathlog$logfile quit EOT This is ...
0
votes
1answer
44 views

Bash variable echoing 0

I'm trying to create a simple bash script but I can't get the variable handling right. When the RESULT variable receives an empty value it does not echo "-1", it returns a 0. Why does bash turn the ...
-1
votes
0answers
26 views

How to test sftp connections to multiple servers with different username and passwords?

I have a situation where i need to check sftp connectivity to hundred of servers having different username and password combinations. I want to do it using a shell script but i am not sure how to do ...
0
votes
0answers
26 views

Bash Script that changes WLAN channel and set monitor mode

I ran into a bit of a weird problem (or at least in my opinion it is). When I execute the following command: sudo iwconfig wlx00c0ca959fe2 mode monitor channel 1 Everything is fine, WLAN adapter is ...
3
votes
1answer
197 views

What is the use of declare with option -t

If you call the command help declare. You will see the following information: -t NAME : to make NAMEs have the `trace' attribute Is there any example that demonstrates the use of this option. I ...
0
votes
1answer
24 views

calling associative arrays [closed]

Team, am setting some variables in an associative array but its output is not resulting anything.. any hint?> #/bin/bash #IOEngine="psync" #TestType="read" IOEngine="libaio" TestType="randread" ...
0
votes
1answer
42 views

Broken pipe only in Jenkins

I have a script that works just fine locally. But when I run it in Jenkins, I get Error: writing output failed: Broken pipe. My question is how can I fix this to work in jenkins? Now for the context ...
5
votes
2answers
260 views

How to generate list of *all* available commands and functions?

In Linux (I am using CentOS 7), there is a built in functionality to view all runnable commands. The command is run by pressing tab twice in the console followed by the prompt: Display all 1130 ...
2
votes
2answers
44 views

How to tune this `scratch` alias for Bash by using the `PS2` variable?

Very often, I need to quickly type some lines of characters (for instance for simplifying a mathematical expression) and then discard the whole stuff. Of course, I generally have several running ...
1
vote
1answer
25 views

Make auto completion options remain on screen in zsh, like bash

As Apple rolled out the first developer previews of macOS Catalina, it seems like they have made the default shell into zsh, instead of the good old bash. I've kept myself at Mojave, but nonetheless I'...
-1
votes
2answers
38 views

“Filename” vs “Filename-git”

What is the meaning of files that end in -git? For example, I searched in a Terminal for "xcb-imdkit" then pressed tab. xcb-imdkit comes up, as well as "xcb-imdkit-git".
11
votes
2answers
1k views

Why do I seem to lose data using this bash pipe construction?

I am trying to combine a few programs like so (please ignore any extra includes, this is heavy work-in-progress): pv -q -l -L 1 < input.csv | ./repeat <(nc "host" 1234) Where the source of ...
0
votes
3answers
59 views

How to hand over arguments containing “-” in Bash? [duplicate]

I tried to use the grep command to search for a string like -R in a file. But the command thinks, that I am trying to hand over an option like -i for ignore case.