what does "echo $$" do?
so question, what does "echo $$" do?
some people are saying that it prints the PID of the current instance of the shell you are on
other people are saying that it prints the PID of "a" or "the" noscript that's currently executing?
which is it? or is it both?
thank you
https://redd.it/1fwp9lf
@r_bash
so question, what does "echo $$" do?
some people are saying that it prints the PID of the current instance of the shell you are on
other people are saying that it prints the PID of "a" or "the" noscript that's currently executing?
which is it? or is it both?
thank you
https://redd.it/1fwp9lf
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
How do I replace part of a line with the output of a variable?
Hi all,
I am writing a noscript that will update my IPv4 on my Wireguard server as my dynamic IP changes. Here is what I have so far:
#! /bin/bash
CurrentIP= curl -S -s -o /dev/null http://ipinfo.io/ip
WireguardIP= grep -q "pivpnHOST=" /etc/pivpn/wireguard/setupVars.conf |tr -d 'pivpnHOST='
if "$Current_IP" = "$Wireguard_IP" ;then
exit
else
#replace WireguardIP with CurrentIP in setupVars.conf
fi
exit 0
when trying to find my answer I searched through stack overflow and think I need to use awk -v, however; I don't know how to in this case. Any pointers would be appreciated.
https://redd.it/1fwxq9l
@r_bash
Hi all,
I am writing a noscript that will update my IPv4 on my Wireguard server as my dynamic IP changes. Here is what I have so far:
#! /bin/bash
CurrentIP= curl -S -s -o /dev/null http://ipinfo.io/ip
WireguardIP= grep -q "pivpnHOST=" /etc/pivpn/wireguard/setupVars.conf |tr -d 'pivpnHOST='
if "$Current_IP" = "$Wireguard_IP" ;then
exit
else
#replace WireguardIP with CurrentIP in setupVars.conf
fi
exit 0
when trying to find my answer I searched through stack overflow and think I need to use awk -v, however; I don't know how to in this case. Any pointers would be appreciated.
https://redd.it/1fwxq9l
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Getting the “logname” of a PID
Say I log into a box with account “abc”. I su to account “def” and run a noscript, helloworld.sh, as account “def”. If I run a
Context: I have a noscript where I allow accounts to impersonate others. The impersonation is logged in the noscript’s log via the logname command, but I also have a “current users” report where I can see who’s currently running the noscript. I’d like the current users report to show that, while John is running the noscript, it’s actually Joe who’s impersonating John via an su.
I’ve tried ps -U and ps -u, but obviously, that didn’t work.
https://redd.it/1fx6n52
@r_bash
Say I log into a box with account “abc”. I su to account “def” and run a noscript, helloworld.sh, as account “def”. If I run a
ps -ef | grep helloworld, I will see the noscript running with account “def” as the owner. Is there a way I can map that back to the OG account “abc” to store that value into a variable? Context: I have a noscript where I allow accounts to impersonate others. The impersonation is logged in the noscript’s log via the logname command, but I also have a “current users” report where I can see who’s currently running the noscript. I’d like the current users report to show that, while John is running the noscript, it’s actually Joe who’s impersonating John via an su.
I’ve tried ps -U and ps -u, but obviously, that didn’t work.
https://redd.it/1fx6n52
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Shell noscripting projects for 1 yoe helpdesk to get promoted to a new role?
What could that be?(in new company-switch)
https://redd.it/1fx6m6a
@r_bash
What could that be?(in new company-switch)
https://redd.it/1fx6m6a
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
How do I finish a pipe early?
Hi.
I have this noscript that is supposed to get me the keyframes between two timestamps (in seconds). I want to use them in order to splice a video without having to reencode it at all. I also want to use ffmpeg for this.
My issue is that I have a big file and I want to finish the processing early under a certain condition. How do I do it from inside of an
I think it's also important to mention that this noscript was written with some chatgpt help, because I can't write awk things at all.
Thank you for your time.
https://pastebin.com/cGEK9EHH
#!/bin/bash
set -x #echo on
SOURCEVIDEO="$1"
STARTTIME="$2"
ENDTIME="$3"
# Get total number of frames for progress tracking
TOTALFRAMES=$(ffprobe -v error -selectstreams v:0 -countpackets -showentries stream=nbreadpackets -of csv=p=0 "$SOURCEVIDEO")
if -z "$TOTAL_FRAMES" ; then
echo "Error: Unable to retrieve the total number of frames."
exit 1
fi
# Initialize variables for tracking progress
framesprocessed=0
startframe=""
endframe=""
startdiff=999999
enddiff=999999
# Process frames
ffprobe -showframes -selectstreams v:0 \
-printformat csv "$SOURCEVIDEO" 2>&1 |
grep -n frame,video,0 |
awk 'BEGIN { FS="," } { print $1 " " $5 }' |
sed 's/:frame//g' |
awk -v start="$STARTTIME" -v end="$ENDTIME" '
BEGIN {
FS=" ";
print "start";
startframe="";
endframe="";
startdiff=999999;
enddiff=999999;
betweenframes="";
print "startend";
}
{
print "processing";
current = $2;
if (current > end) {
exit;
}
if (startframe == "" && current >= start) {
startframe = $1;
startdiff = current - start;
} else if (current >= start && (current - start) < startdiff) {
startframe = $1;
startdiff = current - start;
}
if (current <= end && (end - current) < enddiff) {
endframe = $1;
enddiff = end - current;
}
if (current >= start && current <= end) {
betweenframes = betweenframes $1 ",";
}
}
END {
print "\nProcessing completed."
print "Closest keyframe to start time: " startframe;
print "Closest keyframe to end time: " endframe;
print "All keyframes between start and end:";
print substr(betweenframes, 1, length(betweenframes)-1);
}'
Edit: I have debugged it a little more and I had a typo but I think I have a problem with sed.
ffprobe -showframes -selectstreams v:0 \
-printformat csv "$SOURCEVIDEO" 2>&1 |
grep -n frame,video,0 |
awk 'BEGIN { FS="," } { print $1 " " $5 }' |
sed 's/:frame//g'
The above doesn't output anything, but before
38:frame 9009
39:frame 10010
40:frame 11011
41:frame 12012
42:frame 13013
43:frame 14014
44:frame 15015
45:frame 16016
46:frame 17017
47:frame 18018
48:frame 19019
49:frame 20020
50:frame 21021
51:frame 22022
52:frame 23023
53:frame 24024
54:frame 25025
55:frame 26026
I'm not sure if
https://redd.it/1fxhx2n
@r_bash
Hi.
I have this noscript that is supposed to get me the keyframes between two timestamps (in seconds). I want to use them in order to splice a video without having to reencode it at all. I also want to use ffmpeg for this.
My issue is that I have a big file and I want to finish the processing early under a certain condition. How do I do it from inside of an
awk noscript? I've already used this exit in the early finish condition, but I think it only finishes the awk noscript early. I also don't know if it runs, because I don't know whether it's possible to print out some debug info when using awk. Edit: I've added print "blah"; at the beginning of the middle clause and I don't see it being printed, so I'm probably not matching anything or something? print inside of BEGIN does get printed. :/ I think it's also important to mention that this noscript was written with some chatgpt help, because I can't write awk things at all.
Thank you for your time.
https://pastebin.com/cGEK9EHH
#!/bin/bash
set -x #echo on
SOURCEVIDEO="$1"
STARTTIME="$2"
ENDTIME="$3"
# Get total number of frames for progress tracking
TOTALFRAMES=$(ffprobe -v error -selectstreams v:0 -countpackets -showentries stream=nbreadpackets -of csv=p=0 "$SOURCEVIDEO")
if -z "$TOTAL_FRAMES" ; then
echo "Error: Unable to retrieve the total number of frames."
exit 1
fi
# Initialize variables for tracking progress
framesprocessed=0
startframe=""
endframe=""
startdiff=999999
enddiff=999999
# Process frames
ffprobe -showframes -selectstreams v:0 \
-printformat csv "$SOURCEVIDEO" 2>&1 |
grep -n frame,video,0 |
awk 'BEGIN { FS="," } { print $1 " " $5 }' |
sed 's/:frame//g' |
awk -v start="$STARTTIME" -v end="$ENDTIME" '
BEGIN {
FS=" ";
print "start";
startframe="";
endframe="";
startdiff=999999;
enddiff=999999;
betweenframes="";
print "startend";
}
{
print "processing";
current = $2;
if (current > end) {
exit;
}
if (startframe == "" && current >= start) {
startframe = $1;
startdiff = current - start;
} else if (current >= start && (current - start) < startdiff) {
startframe = $1;
startdiff = current - start;
}
if (current <= end && (end - current) < enddiff) {
endframe = $1;
enddiff = end - current;
}
if (current >= start && current <= end) {
betweenframes = betweenframes $1 ",";
}
}
END {
print "\nProcessing completed."
print "Closest keyframe to start time: " startframe;
print "Closest keyframe to end time: " endframe;
print "All keyframes between start and end:";
print substr(betweenframes, 1, length(betweenframes)-1);
}'
Edit: I have debugged it a little more and I had a typo but I think I have a problem with sed.
ffprobe -showframes -selectstreams v:0 \
-printformat csv "$SOURCEVIDEO" 2>&1 |
grep -n frame,video,0 |
awk 'BEGIN { FS="," } { print $1 " " $5 }' |
sed 's/:frame//g'
The above doesn't output anything, but before
sed the output is:38:frame 9009
39:frame 10010
40:frame 11011
41:frame 12012
42:frame 13013
43:frame 14014
44:frame 15015
45:frame 16016
46:frame 17017
47:frame 18018
48:frame 19019
49:frame 20020
50:frame 21021
51:frame 22022
52:frame 23023
53:frame 24024
54:frame 25025
55:frame 26026
I'm not sure if
sed is supposed to printout anything or not though. Probably it is supposed to do so?https://redd.it/1fxhx2n
@r_bash
Pastebin
#!/bin/bashset -x #echo onSOURCE_VIDEO="$1"START_TIME="$2"END_TIME="$3" - Pastebin.com
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
How are if, case, etc implemented internally?
I was thinking about it and I realized I had no idea- how do if, for, while, case, etc, all control the execution of separate commands on other lines? For example
if [ "$thing" == "blah" ]; then
echo "How does it know to not run this command if thing is not blah??"
fi
Is this something only builtin commands have the power to do? Or could if, case, etc, theoretically be implemented as external programs?
https://redd.it/1fxnch3
@r_bash
I was thinking about it and I realized I had no idea- how do if, for, while, case, etc, all control the execution of separate commands on other lines? For example
if [ "$thing" == "blah" ]; then
echo "How does it know to not run this command if thing is not blah??"
fi
Is this something only builtin commands have the power to do? Or could if, case, etc, theoretically be implemented as external programs?
https://redd.it/1fxnch3
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
this will probably be very complex
im tryting to create a noscript where i can pick up a text with some image links in the middle and input that into a tui like less will all the images loaded with ueberzug.
i know that is possible because there are noscripts like ytfzf that is capable of doing something close.
the tool im using to get the texts with image links in the middle is algia(terminal nostr client).
to be honest a vim tui would make it more usable but i dont know if this would be much more complex so something like less but that is capable o loading tui images would be more than enought.
i use alacritty.
https://redd.it/1fxwrw2
@r_bash
im tryting to create a noscript where i can pick up a text with some image links in the middle and input that into a tui like less will all the images loaded with ueberzug.
i know that is possible because there are noscripts like ytfzf that is capable of doing something close.
the tool im using to get the texts with image links in the middle is algia(terminal nostr client).
to be honest a vim tui would make it more usable but i dont know if this would be much more complex so something like less but that is capable o loading tui images would be more than enought.
i use alacritty.
https://redd.it/1fxwrw2
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Does export supposed to create a permanent environment variable?
For many guides for installing packages out there, I always see this as a step to installing the package, for example...
```
export JAVA_HOME=/opt/android-studio/jbr
```
And it does work. It does create a env variable (In the example above JAVA_HOME) but when I close the terminal and the next time I launch the terminal, the env variable is not there and the packages need these variables setup for all sessions.
Am I doing something wrong? Why do many guides tell you to simply run `export` instead of edit the `/etc/profile` file by adding the `export` command to the end of the `/etc/profile` file which will make the env variable in all terminal sessions?
https://redd.it/1fxyffj
@r_bash
For many guides for installing packages out there, I always see this as a step to installing the package, for example...
```
export JAVA_HOME=/opt/android-studio/jbr
```
And it does work. It does create a env variable (In the example above JAVA_HOME) but when I close the terminal and the next time I launch the terminal, the env variable is not there and the packages need these variables setup for all sessions.
Am I doing something wrong? Why do many guides tell you to simply run `export` instead of edit the `/etc/profile` file by adding the `export` command to the end of the `/etc/profile` file which will make the env variable in all terminal sessions?
https://redd.it/1fxyffj
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
I habe 10 hours to learn bash. What would you do?
Hey, people, I have 10 hours of free time to learn simple bash noscripting. Maybe even more.
I already know how to use commands in cli, I worked as a developer for 5 years and even wrote simple DevOps pipelines (using yml in GitHub)
But I want to go deeper, my brain is a mess when it comes to bash
It's embarrassing after 5 years in coding, I know.
I don't even know the difference between bash and shell. I don't know commands and I am freaked out when I have to use CLI.
I want to fix it. It cripples me as a developer.
Do you know a some ebooks or something that can help me organise my brain and learn all of it?
Maybe fun real-world projects that I can spin out in a weekend?
Thank you in advance!
https://redd.it/1fy4xhy
@r_bash
Hey, people, I have 10 hours of free time to learn simple bash noscripting. Maybe even more.
I already know how to use commands in cli, I worked as a developer for 5 years and even wrote simple DevOps pipelines (using yml in GitHub)
But I want to go deeper, my brain is a mess when it comes to bash
It's embarrassing after 5 years in coding, I know.
I don't even know the difference between bash and shell. I don't know commands and I am freaked out when I have to use CLI.
I want to fix it. It cripples me as a developer.
Do you know a some ebooks or something that can help me organise my brain and learn all of it?
Maybe fun real-world projects that I can spin out in a weekend?
Thank you in advance!
https://redd.it/1fy4xhy
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
How can I use a bash/grep search in vim?
Looking at the contents of both /r/bash and /r/vim, it seems the question is best placed here.
I have a working grep term which I want to use in vim.
It's simply
I want to have a search term in vim which jumps to the next line starting with
How can I translate this
It needs to be done in vim since what corrections need to be made to the following line depends on human input.
https://redd.it/1fy5uwe
@r_bash
Looking at the contents of both /r/bash and /r/vim, it seems the question is best placed here.
I have a working grep term which I want to use in vim.
It's simply
grep "^#" malformed_file.tmp | grep '^.\{80\}$'; or in other words: I want to have a search term in vim which jumps to the next line starting with
# which is exactly 80 characters long, not longer.How can I translate this
grep stanza to a vim search?It needs to be done in vim since what corrections need to be made to the following line depends on human input.
https://redd.it/1fy5uwe
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Line counting errors: "ps -ef" piped into "wc -l" returns the wrong number of lines, unless the lines are very short, and I can't see why
**Background:** I have a bash noscript that I want to ensure is always running, but in one and only one instance. I chose to use an entry in `/etc/crontab` to start the noscript every hour or so, but in the noscript itself add a check for any other instances that might be running (and abort quietly if there are other processes than itself that are running). I specifically do not want the hassle of handling lockfiles, especially if the noscript would be killed without cleaning up its lockfile.
**Method:** I use `ps -ef -o pid,cmd` piped into `grep` to find the process\[-es\], followed by `wc -l` to output the number of lines. If this is == 1, there is no *other* process running, and the current process does its thing. Otherwise, i assume some other process is already running, and this one aborts quietly.
**The problem and workaround:** I get too high a number (1 too high) as the output from `wc -l`. I can reproduce it repeatedly if the output from `ps` has lines longer than 80 characters. However, if I limit the output by using `ps -ef --cols=57 -o pid,cmd` (or lower), it works as expected. The actual number is different for different filenames/paths, I initially thought it was related to a default 80 character terminal width but there seems to be more to it.
**Why does this happen? I can use wc -l in other cases with very long lines without any problems.** If I got too few output values, I could perhaps have understood it since wc counts the number of newline characters (not characters at the end of the file if the last line is not terminated by a newline). But this is the opposite.
Here is some proof-of-concept code to reproduce this, for my test noscript "/usr/local/bin/test-only-one.sh":
#!/bin/bash
PROGNAME="$(basename $0)"
PROGFIRSTL="${PROGNAME:0:1}"
GREPSTRING=$(echo "$PROGNAME" | sed "s/^$PROGFIRSTL/\[$PROGFIRSTL]/")# A trailing space is added in the grep statement below
#GREPSTRING="$PROGNAME"# Same results
# Now make sure to grap the currently running program, not "grep" or any editor that has the noscript file open
# BUG: Using a COLCOUNT limit somewhere below 80 works, but having COLCOUNT higher than that limit results in an incorrect output (too high).
# In other words, using a low --cols limit works unless the filename (with path) is too long
COLCOUNT=69
COLCOUNT=70
if [ ! -z "$1" ]; then
COLCOUNT="$1"# Command line option for demo purposes only
fi
NO_OF_RUNNING_PROGRAMS=$(ps -ef --cols=$COLCOUNT -o pid,cmd | \
grep -e '^[[:space:]]*[0-9]*[[:space:]]*[\\]*[_]*[[:space:]]*/bin/bash .*'"$GREPSTRING " | \
wc -l)
DEBUG_PRINT_PS_OUTPUT=true
if $DEBUG_PRINT_PS_OUTPUT; then
echo -e "\t\t[DEBUG]\tNO_OF_RUNNING_PROGRAMS == $NO_OF_RUNNING_PROGRAMS; COLCOUNT == $COLCOUNT; GREPSTRING == \"$GREPSTRING\""
echo -e "\t\t[DEBUG]\tvvv ps output start:"
ps -ef --cols=$COLCOUNT -o pid,cmd | \
grep -e '^[[:space:]]*[0-9]*[[:space:]]*[\\]*[_]*[[:space:]]*/bin/bash .*'"$GREPSTRING " | \
sed 's/^/\t\t\t/'
echo -e "\t\t[DEBUG]\t^^^ ps output stop."
fi
if ((1 == $NO_OF_RUNNING_PROGRAMS)); then
echo -e "\t[OK]\tThis instance (PID $$) is the only instance running"
else
echo -e "\t[ERROR]\tAborting PID $$, since this noscript was already running"
fi
Here are two illustrative outputs, first the intended operation:
`$` [`test-only-one.sh`](http://test-only-one.sh) `57`
[DEBUG]NO_OF_RUNNING_PROGRAMS == 1; COLCOUNT == 57; GREPSTRING == "[t]est-only-one.sh"
[DEBUG]vvv ps output start:
776743 \_ /bin/bash /usr/local/bin/test-only-one.sh 57
[DEBUG]^^^ ps output stop.
[OK]This instance (PID 776743) is the only instance running
**And now when it fails for some unknown reason:**
`$` [`test-only-one.sh`](http://test-only-one.sh) `58`
[DEBUG]NO_OF_RUNNING_PROGRAMS == 2; COLCOUNT == 58; GREPSTRING == "[t]est-only-one.sh"
[DEBUG]vvv ps
**Background:** I have a bash noscript that I want to ensure is always running, but in one and only one instance. I chose to use an entry in `/etc/crontab` to start the noscript every hour or so, but in the noscript itself add a check for any other instances that might be running (and abort quietly if there are other processes than itself that are running). I specifically do not want the hassle of handling lockfiles, especially if the noscript would be killed without cleaning up its lockfile.
**Method:** I use `ps -ef -o pid,cmd` piped into `grep` to find the process\[-es\], followed by `wc -l` to output the number of lines. If this is == 1, there is no *other* process running, and the current process does its thing. Otherwise, i assume some other process is already running, and this one aborts quietly.
**The problem and workaround:** I get too high a number (1 too high) as the output from `wc -l`. I can reproduce it repeatedly if the output from `ps` has lines longer than 80 characters. However, if I limit the output by using `ps -ef --cols=57 -o pid,cmd` (or lower), it works as expected. The actual number is different for different filenames/paths, I initially thought it was related to a default 80 character terminal width but there seems to be more to it.
**Why does this happen? I can use wc -l in other cases with very long lines without any problems.** If I got too few output values, I could perhaps have understood it since wc counts the number of newline characters (not characters at the end of the file if the last line is not terminated by a newline). But this is the opposite.
Here is some proof-of-concept code to reproduce this, for my test noscript "/usr/local/bin/test-only-one.sh":
#!/bin/bash
PROGNAME="$(basename $0)"
PROGFIRSTL="${PROGNAME:0:1}"
GREPSTRING=$(echo "$PROGNAME" | sed "s/^$PROGFIRSTL/\[$PROGFIRSTL]/")# A trailing space is added in the grep statement below
#GREPSTRING="$PROGNAME"# Same results
# Now make sure to grap the currently running program, not "grep" or any editor that has the noscript file open
# BUG: Using a COLCOUNT limit somewhere below 80 works, but having COLCOUNT higher than that limit results in an incorrect output (too high).
# In other words, using a low --cols limit works unless the filename (with path) is too long
COLCOUNT=69
COLCOUNT=70
if [ ! -z "$1" ]; then
COLCOUNT="$1"# Command line option for demo purposes only
fi
NO_OF_RUNNING_PROGRAMS=$(ps -ef --cols=$COLCOUNT -o pid,cmd | \
grep -e '^[[:space:]]*[0-9]*[[:space:]]*[\\]*[_]*[[:space:]]*/bin/bash .*'"$GREPSTRING " | \
wc -l)
DEBUG_PRINT_PS_OUTPUT=true
if $DEBUG_PRINT_PS_OUTPUT; then
echo -e "\t\t[DEBUG]\tNO_OF_RUNNING_PROGRAMS == $NO_OF_RUNNING_PROGRAMS; COLCOUNT == $COLCOUNT; GREPSTRING == \"$GREPSTRING\""
echo -e "\t\t[DEBUG]\tvvv ps output start:"
ps -ef --cols=$COLCOUNT -o pid,cmd | \
grep -e '^[[:space:]]*[0-9]*[[:space:]]*[\\]*[_]*[[:space:]]*/bin/bash .*'"$GREPSTRING " | \
sed 's/^/\t\t\t/'
echo -e "\t\t[DEBUG]\t^^^ ps output stop."
fi
if ((1 == $NO_OF_RUNNING_PROGRAMS)); then
echo -e "\t[OK]\tThis instance (PID $$) is the only instance running"
else
echo -e "\t[ERROR]\tAborting PID $$, since this noscript was already running"
fi
Here are two illustrative outputs, first the intended operation:
`$` [`test-only-one.sh`](http://test-only-one.sh) `57`
[DEBUG]NO_OF_RUNNING_PROGRAMS == 1; COLCOUNT == 57; GREPSTRING == "[t]est-only-one.sh"
[DEBUG]vvv ps output start:
776743 \_ /bin/bash /usr/local/bin/test-only-one.sh 57
[DEBUG]^^^ ps output stop.
[OK]This instance (PID 776743) is the only instance running
**And now when it fails for some unknown reason:**
`$` [`test-only-one.sh`](http://test-only-one.sh) `58`
[DEBUG]NO_OF_RUNNING_PROGRAMS == 2; COLCOUNT == 58; GREPSTRING == "[t]est-only-one.sh"
[DEBUG]vvv ps
output start:
776756 \_ /bin/bash /usr/local/bin/test-only-one.sh 58 S
[DEBUG]^^^ ps output stop.
[ERROR]Aborting PID 776756, since this noscript was already running
https://redd.it/1fy5ho0
@r_bash
776756 \_ /bin/bash /usr/local/bin/test-only-one.sh 58 S
[DEBUG]^^^ ps output stop.
[ERROR]Aborting PID 776756, since this noscript was already running
https://redd.it/1fy5ho0
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Another PS1 prompt question
my__git_ps1() {
local GIT_PS1=$(__git_ps1)
if [ ! -z "$GIT_PS1" -a "$GIT_PS1" != "" ] ; then echo '\[\e[m\]\[\e[96m\]'$GIT_PS1; fi
}
PS1='\[\e[92m\][\u@\h\[\e[m\] \[\e[93m\]\W'$(my__git_ps1)']\$\[\e[m\] '
Problem? Changing directories does not mutate `GIT_PS1`, so when you `cd ..` from a repo, you still see the past value of `GIT_PS1`, and when you `cd repo` from a non-repo, you don't see the `GIT_PS1`. I know `my__git_ps1` runs every time I change directories, otherwise the vanilla calling `__git_ps1` from `PS1` wouldn't work. So, is `my__git_ps1` maybe caching `GIT_PS1` by any chance?
https://redd.it/1fycuyf
@r_bash
my__git_ps1() {
local GIT_PS1=$(__git_ps1)
if [ ! -z "$GIT_PS1" -a "$GIT_PS1" != "" ] ; then echo '\[\e[m\]\[\e[96m\]'$GIT_PS1; fi
}
PS1='\[\e[92m\][\u@\h\[\e[m\] \[\e[93m\]\W'$(my__git_ps1)']\$\[\e[m\] '
Problem? Changing directories does not mutate `GIT_PS1`, so when you `cd ..` from a repo, you still see the past value of `GIT_PS1`, and when you `cd repo` from a non-repo, you don't see the `GIT_PS1`. I know `my__git_ps1` runs every time I change directories, otherwise the vanilla calling `__git_ps1` from `PS1` wouldn't work. So, is `my__git_ps1` maybe caching `GIT_PS1` by any chance?
https://redd.it/1fycuyf
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
This media is not supported in your browser
VIEW IN TELEGRAM
I have made ipfetch in bash! A neofetch like tool that can lookup IPs!
https://redd.it/1fykwx0
@r_bash
https://redd.it/1fykwx0
@r_bash
Symlinks with spaces in folder name
The following works except for folders with spaces in the name.
#!/bin/bash
cd /var/packages || exit
while read -r link target; do
echo "link: $link" # debug
echo -e "target: $target \n" # debug
done < <(find . -maxdepth 2 -type l -ls | grep volume | grep target | cut -d'.' -f2- | sed 's/ ->//')
Like "Plex Media Server":
link: /Docker/target
target: /volume1/@appstore/Docker
link: /Plex\
target: Media\ Server/target /volume1/@appstore/Plex\ Media\ Server
Instead of:
link: /Plex\ Media\ Server/target
target: /volume1/@appstore/Plex\ Media\ Server
What am I doing wrong?
​
https://redd.it/1fylclc
@r_bash
The following works except for folders with spaces in the name.
#!/bin/bash
cd /var/packages || exit
while read -r link target; do
echo "link: $link" # debug
echo -e "target: $target \n" # debug
done < <(find . -maxdepth 2 -type l -ls | grep volume | grep target | cut -d'.' -f2- | sed 's/ ->//')
Like "Plex Media Server":
link: /Docker/target
target: /volume1/@appstore/Docker
link: /Plex\
target: Media\ Server/target /volume1/@appstore/Plex\ Media\ Server
Instead of:
link: /Plex\ Media\ Server/target
target: /volume1/@appstore/Plex\ Media\ Server
What am I doing wrong?
​
https://redd.it/1fylclc
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Assistance requested with a backup noscript for an Android tablet
BACKGROUND:
I have been endeavouring to update my Android tablet with different versions of this noscript and even before I set my mind on realising this noscript in particular and have been at it for quite some time, but I have so far not been completely successful. It is almost there.
My Termux Linux userland environment is a bit of a legacy ecosystem. I have tried to set up my system well, but there are anomalies and inconsistencies. I have just been teaching myself and learning on the fly.
In executing earlier versions of this noscript, it kept on maxing out the memory of my microSD, but there should have been more than ample space. The backup directories would be hundreds of times larger than the size of the original source directories. I realised it was infinite loops caused by nested symbolic links and probably other reasons that I have not yet identified. This is the reason for the structure of the noscript and the excessive logging.
The problems are few (I hope):
1. A virulent unbounded variable in the backup_files array. I just haven't been able to fix it and I don't know why.
2. I had a lot of problems with terminating all the spawned processes. Some of them were really sneaky. Hence, the KILLSWITCH. But I just can't get it to work and I don't know why.
https://pastebin.com/QrHgCiQ4
Any assistance to help me bash this into shape would be most appreciated.
https://redd.it/1fykj4r
@r_bash
BACKGROUND:
I have been endeavouring to update my Android tablet with different versions of this noscript and even before I set my mind on realising this noscript in particular and have been at it for quite some time, but I have so far not been completely successful. It is almost there.
My Termux Linux userland environment is a bit of a legacy ecosystem. I have tried to set up my system well, but there are anomalies and inconsistencies. I have just been teaching myself and learning on the fly.
In executing earlier versions of this noscript, it kept on maxing out the memory of my microSD, but there should have been more than ample space. The backup directories would be hundreds of times larger than the size of the original source directories. I realised it was infinite loops caused by nested symbolic links and probably other reasons that I have not yet identified. This is the reason for the structure of the noscript and the excessive logging.
The problems are few (I hope):
1. A virulent unbounded variable in the backup_files array. I just haven't been able to fix it and I don't know why.
2. I had a lot of problems with terminating all the spawned processes. Some of them were really sneaky. Hence, the KILLSWITCH. But I just can't get it to work and I don't know why.
https://pastebin.com/QrHgCiQ4
Any assistance to help me bash this into shape would be most appreciated.
https://redd.it/1fykj4r
@r_bash
Pastebin
persistent_integrity_validation_backup8.sh - Pastebin.com
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
How do I delete letters in vi bash?
Made this MESS of D’s and A’s now I don’t know how to delete it. Pressing X just replaces the letter and the delete button doesn’t work. Please help.
https://redd.it/1fyphnr
@r_bash
Made this MESS of D’s and A’s now I don’t know how to delete it. Pressing X just replaces the letter and the delete button doesn’t work. Please help.
https://redd.it/1fyphnr
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
How to make a symbolic link to file with exclamation point '!' in directory?
The file is located in:
Same output results when placing a single quotation around first exclamation point.
I add quote around the first exclamation point plus one backslash before:
ls -lh displays:
When I instead just do a backslash:
ls -lh displays:
https://redd.it/1fz1t4h
@r_bash
The file is located in:
/media/hdd2/video/Title 1!/noscript 1!.mp4ln -sn "/media/hdd2/video/Title 1!/noscript 1!.mp4" "noscript 1!".mp4 results in: bash: !/Title: event not foundSame output results when placing a single quotation around first exclamation point.
I add quote around the first exclamation point plus one backslash before:
/media/hdd2/video/Title 1'\!'/noscript 1!.mp4ls -lh displays:
noscript 1!.mp4 -> '/media/hdd2/video/Title 1'\''\!'\''/noscript 1!.mp4'When I instead just do a backslash:
/media/hdd2/video/Title 1\!/noscript 1!.mp4ls -lh displays:
noscript 1!.mp4 -> /media/hdd2/video/Title 1\!/noscript 1!.mp4https://redd.it/1fz1t4h
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Suitable projects to make using bash/linux POSIX commands?
https://en.wikipedia.org/wiki/List_of_POSIX_commands
I've created about 5 short noscripts. They're related to :
- SSL certificate expiry monitor and alert system
- Hangman trivia game
- Weather api redirection and check today's weather
and so on.
I want to indulge into something interesting now. I am a beginner (only 1 yoe with linux sysadmin and slowly starting noscripting)..
Someone suggested that I should write my own netcat? nmap? However, my interests doesn't lie there. I like to make games, guis, and and do data analysis using awk etc.
I like something that is practically applicable and suitable for bash as well. Something, I can use for real applications. SSL certificate expiry checker was one of them I really loved.
https://redd.it/1fz2ryj
@r_bash
https://en.wikipedia.org/wiki/List_of_POSIX_commands
I've created about 5 short noscripts. They're related to :
- SSL certificate expiry monitor and alert system
- Hangman trivia game
- Weather api redirection and check today's weather
and so on.
I want to indulge into something interesting now. I am a beginner (only 1 yoe with linux sysadmin and slowly starting noscripting)..
Someone suggested that I should write my own netcat? nmap? However, my interests doesn't lie there. I like to make games, guis, and and do data analysis using awk etc.
I like something that is practically applicable and suitable for bash as well. Something, I can use for real applications. SSL certificate expiry checker was one of them I really loved.
https://redd.it/1fz2ryj
@r_bash
Changing color theme codes
Hello everybody. Sorry for bad format, just started to learn this stuff.
My google-fu has failed me, so i am asking for advice here.
I know how to set color scheme in tty, by adding something like
or with echo
and i have added this to my .bashrc
But this method does not work for terminal emulators.
Closest i got was with
but i can not change color codes for other 0-15 colors.
I have also tried googh, but that just downloads theme profiles, and i cant save that in bashrc for portability.
Anyway. Any help is welcome.
https://redd.it/1fz2yy9
@r_bash
Hello everybody. Sorry for bad format, just started to learn this stuff.
My google-fu has failed me, so i am asking for advice here.
I know how to set color scheme in tty, by adding something like
if [ "$TERM" = "linux" ]; then\printf %b '\\e\]P0282a36' # redefine 'black'``\printf %b '\\e\]P86272a4' # redefine 'bright-black'``...fior with echo
echo -en "\e]P0222222" #blackecho -en "\e]P8666666" #darkgrey....and i have added this to my .bashrc
But this method does not work for terminal emulators.
Closest i got was with
echo -ne '\e]11;#808080\e\\' # change backgroundecho -ne '\e]10;#000000\e\\' # change foregroundbut i can not change color codes for other 0-15 colors.
I have also tried googh, but that just downloads theme profiles, and i cant save that in bashrc for portability.
Anyway. Any help is welcome.
https://redd.it/1fz2yy9
@r_bash
GitHub
GitHub - Gogh-Co/Gogh: Gogh is a collection of color schemes for various terminal emulators, including Gnome Terminal, Pantheon…
Gogh is a collection of color schemes for various terminal emulators, including Gnome Terminal, Pantheon Terminal, Tilix, and XFCE4 Terminal also compatible with iTerm on macOS. - Gogh-Co/Gogh