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. For shell scripts with errors/syntax errors, please check them with the shellcheck program (or in the web shellcheck server at https://shellcheck.net) before posting here.
26,711
questions
0
votes
1
answer
74
views
Redirect output to file but never create empty file
Is there a way to redirect output of a command that never stops to a file but only create the file once the command actually produces output?
Here is what I have so far:
target=logs/$(date +%Y%m%dT%H%...
-1
votes
1
answer
41
views
Variables concatenated with & are not defined in subsequent commands
I would like to know why the following shows an empty dialog box:
testvar="hello" & zenity --info --text "${testvar}"
While this works:
testvar="hello"; zenity --...
0
votes
1
answer
31
views
expect - repeatably send "\n\r" before a match expect
I need to netcat a U-Boot and perform NAND script and I use below script
spawn netcat -lup 6666
expect "Hit any key to stop autoboot"
#autoboot counts down from 3 to 0 and somehow one or ...
6
votes
4
answers
953
views
How to make Bash remove quotes after parameter expansion?
Consider the following Bash script:
args="--var 'lddpro_subdomain=prodcopy-lddpro' --var 'partner_subdomain=prodcopy-partner' --var 'model_design_subdomain=prodcopy-model-design'"
for x in ${...
1
vote
3
answers
72
views
Bash: sum a number present in N lines before a given pattern
I have a kdenlive project file (which is basically a xml file) with a lot of text clips inside. I need to bulk edit the x coordinate of a certain text that appears multiple times. This is an example:
...
-2
votes
2
answers
65
views
bash script replace credentials in json file
I have json file like this:
{
"sdpSemantics": "unified-plan",
"iceServers": [
{
"urls": "stun:1.1.1.1:3478"
},
{
"...
0
votes
2
answers
66
views
Bash scripting: Last line - "exit" - necessary?
another basic, innocent question:
When you make a bash script, you could close it with, you could type in as last line
of the script, exit,
echo "Hello world!"
exit
, is it advised, should ...
0
votes
2
answers
55
views
Bash scripting: When to use variable, when function?
basic, innocent question:
In bash scripting, why ever using a function, if one can set a variable containing command substitution with the essence of the function - a certain command or set of ...
0
votes
1
answer
36
views
adding date and variable name to log file and generate a new one
I am trying to run a bash script on daily basis which generates a log file.
#!/bin/bash
exec 3>&1 4>&2
trap 'exec 2>&4 1>&3' 0 1 2 3
exec 1>logfile.output 2>&1
(
...
-1
votes
1
answer
52
views
how to omit/ignore/remove lines starting with local/ using awk
Variable _RESULT contains an output of pacinfo --verbose local/jre.
Using awk script (by Ed Morton - thanks to him!):
awk '{
match($0,/:[[:space:]]*/)
nextTag = substr($0,1,RSTART-1)
...
0
votes
1
answer
28
views
stdin redirection from /dev/tcp/localhost/port
I'm trying to get my head around some TCP-related topics, and have been experimenting:
The following works fine:
Process A: nc -l 12345 | wc -c
Process B: </dev/random head -c 1k > /dev/tcp/...
-3
votes
1
answer
83
views
Find files in a directory modified in the last 24 hours without using the "find" command [closed]
Is there a way to find the files modified in a specific directory in the last 24 hours without using the find command, using only the ls command?
7
votes
2
answers
541
views
Bash: return failure from subshell when any command fails
I have a complex script where I generally test each command individually for success. However, there are cases where I have to carry out a sequence of simple operations, and I'd prefer to get an exit ...
0
votes
1
answer
45
views
Running command 'cat /proc/<pid>/stat | cut -d" " -f29' to get stack pointer , is always showing stack pointer as zero
Iam trying to get the stack pointer of some thread using the /proc//stat, whenever i run the command,cat /proc/<pid>/stat | cut -d" " -f29 i end up getting zero, but when i run sudo ...
0
votes
2
answers
111
views
Terminating the whole pipeline at once when its last process ends
Given the pipeline
printf '%s\n' 1 2 3 4 5 6 7 8 9 |
while read -r num
do
echo "$num" > /dev/stderr
echo "$num"
done |
while read -r num
do
echo $(( $num * 10 ))
[ &...