Are there any tools to analyse/modify colours directly from a bash noscript?
I am on Arch Linux and I am using pywal to generate a colour palette from my wallpaper, which I then use throughout my system. In particular, i have a bash noscript which grabs these colours and uses them for polybar. The problem is that sometimes these colours do not have enough contrast, and the bar is hard to read. Is there any tool that would allow me to check the readability of my colours, and modify them accordingly, directly from my noscript? If not, how should I be approaching this issue?
https://redd.it/14pfnqk
@r_bash
I am on Arch Linux and I am using pywal to generate a colour palette from my wallpaper, which I then use throughout my system. In particular, i have a bash noscript which grabs these colours and uses them for polybar. The problem is that sometimes these colours do not have enough contrast, and the bar is hard to read. Is there any tool that would allow me to check the readability of my colours, and modify them accordingly, directly from my noscript? If not, how should I be approaching this issue?
https://redd.it/14pfnqk
@r_bash
GitHub
GitHub - dylanaraps/pywal: 🎨 Generate and change color-schemes on the fly.
🎨 Generate and change color-schemes on the fly. Contribute to dylanaraps/pywal development by creating an account on GitHub.
Help in determining if I should use if/then or case/esac or what?
I am trying to write a BASH Script for use at work and I am in need of assistance. The noscript I m writing will need operator input and run in sections depending on the users input. What I would like the noscript to do is ask the user how many times it needs to run the subroutine or at the end of each subroutine ask if they would like to continue with next subroutine.
We process files at work sometimes 1 sometimes 3 or 4 or 5. I would like the noscript to ask the user how many files the user is interested in processing and have the noscript run the subroutines for that many.
I don’t know its I should use if/then or case/ecase or whatever else to structure the noscript with.
Following is a step by step of what im intending to do:
Step 1- Ask user how many file values it wants to process
Step 2- Start processing the first file values saving variable values to print out at the end of the noscript
Step 3- Ask the user if they would like to continue
Step 3- Continue to the next file saving its variables to print out at the end also
Step 4- After the last file is processed print the values of the variables from each section
If I set it up for say 5 sections this will cover a number up to what we can do during the day. After it comes to the end of each section if User Input Yes/No to continue with another until the final is reached that would be good. The at the end when the user is asked do you want to continue processing and the answer no it prints the variables retrieved from the different sections.
https://redd.it/14o87vc
@r_bash
I am trying to write a BASH Script for use at work and I am in need of assistance. The noscript I m writing will need operator input and run in sections depending on the users input. What I would like the noscript to do is ask the user how many times it needs to run the subroutine or at the end of each subroutine ask if they would like to continue with next subroutine.
We process files at work sometimes 1 sometimes 3 or 4 or 5. I would like the noscript to ask the user how many files the user is interested in processing and have the noscript run the subroutines for that many.
I don’t know its I should use if/then or case/ecase or whatever else to structure the noscript with.
Following is a step by step of what im intending to do:
Step 1- Ask user how many file values it wants to process
Step 2- Start processing the first file values saving variable values to print out at the end of the noscript
Step 3- Ask the user if they would like to continue
Step 3- Continue to the next file saving its variables to print out at the end also
Step 4- After the last file is processed print the values of the variables from each section
If I set it up for say 5 sections this will cover a number up to what we can do during the day. After it comes to the end of each section if User Input Yes/No to continue with another until the final is reached that would be good. The at the end when the user is asked do you want to continue processing and the answer no it prints the variables retrieved from the different sections.
https://redd.it/14o87vc
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Help optimizing my box drawing function
drawbox() {
tput clear
# gettermsize
horiz="$((COLUMNS - 1))"
# vert="$((LINES - 2 ))"
vert="$LINES"
itera=1
# boxchar0="╭" boxchar1="╮" boxchar2="╰" boxchar3="╯" boxchar4="│"
# boxchar5="─" boxchar6="┑" boxchar7="┎" boxchar8="├" boxchar9="┤"
# put corner left & right top
# and then top line
cuphome && cupxeol && printf '╭'
perl -E "print '─' x $horiz"
cupright 1 && printf '╮'
# input vertical lines on both sides
for ((itera=1; itera<vert; itera++)); do
tput cup "$itera" 0 && printf "│"
tput cup "$itera" "$horiz" && printf "│"
done
# put left & right bottom corner
# and then top line
cup "$vert" 0 && cupxeol && printf '╰'
perl -E "print '─' x $horiz"
cupright 1 && printf '╯'
# put left & right bottom middle delim
# and then mid-line
cup "$((vert - 2))" 0 && cupxeol && printf '├'
perl -E "print '─' x $horiz"
cupright 1 && printf '┤'
}
So I have this noscript that I'm writing, it's pretty large at this point and it's still in it's early stages called [catnip](https://raw.githubusercontent.com/sweetbbak/catnip/main/cn). It is a little command console that lets you pick a directory and shuffle through the images in that directory. I'm on my 2nd or 3rd re-write right now and I'm having trouble optimizing some of these core functions, the worst one is this box drawing function. Its like Box() in C from Ncurses except that it has a little command line box at the bottom.
The main issues that I'm running into are speed, trouble writing unicode characters and portability. I'm using Perl here because it can easily handle unicode characters and its far far faster than using tput.
I'm curious if you all would have some advice here? I'd like to use a bash builtin instead of Perl and I'd really like to speed this up. It's not so bad with perl and only redrawing when the box gets destroyed but I'm still not happy with it.
# cup in the above function is defined as:
# Cursor to absolute position
cup() { printf '\e[%s;%sH' "$1" "$2" ; }
# Erase from cursor to end of line
cupxeol() { printf '\e[K'; }
# Cursor 0, 0
cuphome() { printf '\eH' ; }
Im using this in place of Tput but I'm open to using that instead. In my mind I felt going top left box char, across the top, top right box char... then each side and then the bottom horizontal bar and left + right box characters, then the middle line with a special right and left character on each edge.
The repo has three videos in it that show it in action if you're curious. One weird side-effect of another function is that the characters are colored blue, but only after the "gradient" function is called that takes a string and divides it up to make a color gradient. I'm sure the entire thing is pretty rough but any help would be appreciated.
[https://redd.it/14nnh95
@r_bash
drawbox() {
tput clear
# gettermsize
horiz="$((COLUMNS - 1))"
# vert="$((LINES - 2 ))"
vert="$LINES"
itera=1
# boxchar0="╭" boxchar1="╮" boxchar2="╰" boxchar3="╯" boxchar4="│"
# boxchar5="─" boxchar6="┑" boxchar7="┎" boxchar8="├" boxchar9="┤"
# put corner left & right top
# and then top line
cuphome && cupxeol && printf '╭'
perl -E "print '─' x $horiz"
cupright 1 && printf '╮'
# input vertical lines on both sides
for ((itera=1; itera<vert; itera++)); do
tput cup "$itera" 0 && printf "│"
tput cup "$itera" "$horiz" && printf "│"
done
# put left & right bottom corner
# and then top line
cup "$vert" 0 && cupxeol && printf '╰'
perl -E "print '─' x $horiz"
cupright 1 && printf '╯'
# put left & right bottom middle delim
# and then mid-line
cup "$((vert - 2))" 0 && cupxeol && printf '├'
perl -E "print '─' x $horiz"
cupright 1 && printf '┤'
}
So I have this noscript that I'm writing, it's pretty large at this point and it's still in it's early stages called [catnip](https://raw.githubusercontent.com/sweetbbak/catnip/main/cn). It is a little command console that lets you pick a directory and shuffle through the images in that directory. I'm on my 2nd or 3rd re-write right now and I'm having trouble optimizing some of these core functions, the worst one is this box drawing function. Its like Box() in C from Ncurses except that it has a little command line box at the bottom.
The main issues that I'm running into are speed, trouble writing unicode characters and portability. I'm using Perl here because it can easily handle unicode characters and its far far faster than using tput.
I'm curious if you all would have some advice here? I'd like to use a bash builtin instead of Perl and I'd really like to speed this up. It's not so bad with perl and only redrawing when the box gets destroyed but I'm still not happy with it.
# cup in the above function is defined as:
# Cursor to absolute position
cup() { printf '\e[%s;%sH' "$1" "$2" ; }
# Erase from cursor to end of line
cupxeol() { printf '\e[K'; }
# Cursor 0, 0
cuphome() { printf '\eH' ; }
Im using this in place of Tput but I'm open to using that instead. In my mind I felt going top left box char, across the top, top right box char... then each side and then the bottom horizontal bar and left + right box characters, then the middle line with a special right and left character on each edge.
The repo has three videos in it that show it in action if you're curious. One weird side-effect of another function is that the characters are colored blue, but only after the "gradient" function is called that takes a string and divides it up to make a color gradient. I'm sure the entire thing is pretty rough but any help would be appreciated.
[https://redd.it/14nnh95
@r_bash
Quoting value in string w/ multiple matches
I am looking to add some quotes to a string, and am having some issues with doing it with sed:
>$ value='abc=123'
>
>$ echo $value
>
>abc=123
>
>$ echo $value | sed "s/\\(.*\\)=\\(.*\\)/\\1='\\2'/g"
>
>abc='123' <-- This is what I want, with the value quoted
>
>$ value='JAVA_OPTS=-Xms1G -Xmx3G -Dcom.redhat.fips=false'
>
>$ echo $value
>
>JAVA_OPTS=-Xms1G -Xmx3G -Dcom.redhat.fips=false
>
>$ echo $value | sed "s/\\(.*\\)=\\(.*\\)/\\1='\\2'/g"
>
>JAVA_OPTS=-Xms1G -Xmx3G -Dcom.redhat.fips='false' <-- it's picking up the = inside the value
This is for use in a container, so I would rather not add something bulky like perl or python that could do this easier than sed. awk and other basic GNU Utilities are available
https://redd.it/14n4n9g
@r_bash
I am looking to add some quotes to a string, and am having some issues with doing it with sed:
>$ value='abc=123'
>
>$ echo $value
>
>abc=123
>
>$ echo $value | sed "s/\\(.*\\)=\\(.*\\)/\\1='\\2'/g"
>
>abc='123' <-- This is what I want, with the value quoted
>
>$ value='JAVA_OPTS=-Xms1G -Xmx3G -Dcom.redhat.fips=false'
>
>$ echo $value
>
>JAVA_OPTS=-Xms1G -Xmx3G -Dcom.redhat.fips=false
>
>$ echo $value | sed "s/\\(.*\\)=\\(.*\\)/\\1='\\2'/g"
>
>JAVA_OPTS=-Xms1G -Xmx3G -Dcom.redhat.fips='false' <-- it's picking up the = inside the value
This is for use in a container, so I would rather not add something bulky like perl or python that could do this easier than sed. awk and other basic GNU Utilities are available
https://redd.it/14n4n9g
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
A little bash noscript for new Ubuntu users to help them install Flatpak with necessary software center & desktop integrations
https://github.com/hakerdefo/flatjak
https://redd.it/14ldurr
@r_bash
https://github.com/hakerdefo/flatjak
https://redd.it/14ldurr
@r_bash
GitHub
GitHub - hakerdefo/flatjak: Wee helper noscript that installs Flatpak with required integrations & enables the Flathub repo.
Wee helper noscript that installs Flatpak with required integrations & enables the Flathub repo. - GitHub - hakerdefo/flatjak: Wee helper noscript that installs Flatpak with required integratio...
xdotool help - adding in --window breaks things
Can anyone help with this one, using xdotool to do a shift click .
i have to specify the window with --window which seems to make things not work
This works
xdotool keydown shift click 1 keyup shift
Adding --window in this does not.
xdotool keydown --window $windowid shift click --window $windowid 1 keyup --window $windowid shift
the keydown doesnt work for shift as soon as i add in --window
Making it into single lines also has the same issue
xdotool keydown --window $windowid shift
xdotool click --window $windowid 1
xdotool keyup --window $windowid shift
Any suggestions?
Google only finds similar issues or fixes that dont include --window (which is required since its a background window)
https://redd.it/14ltoul
@r_bash
Can anyone help with this one, using xdotool to do a shift click .
i have to specify the window with --window which seems to make things not work
This works
xdotool keydown shift click 1 keyup shift
Adding --window in this does not.
xdotool keydown --window $windowid shift click --window $windowid 1 keyup --window $windowid shift
the keydown doesnt work for shift as soon as i add in --window
Making it into single lines also has the same issue
xdotool keydown --window $windowid shift
xdotool click --window $windowid 1
xdotool keyup --window $windowid shift
Any suggestions?
Google only finds similar issues or fixes that dont include --window (which is required since its a background window)
https://redd.it/14ltoul
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
how to get PID to not appear from a while loop?
So I have a while loop in my PS1 prompt but everytime I open a new terminal a PID shows up at the top like [1\] 28014
I tried 2>/dev/null, it did not work
https://redd.it/14lhf7b
@r_bash
So I have a while loop in my PS1 prompt but everytime I open a new terminal a PID shows up at the top like [1\] 28014
I tried 2>/dev/null, it did not work
https://redd.it/14lhf7b
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Capturing history of bash on exit
I have been using something the TRAP command in my .bashrc file for over 10 years to get a history of all commands run in the shell.
I have this line in my .bashrc:
trap $HOME/bin/save_history.sh EXIT
$ cat bin/save_history.sh
\#!/bin/bash
history > \~/.hist/`date +%d%b%y_%H%M_``echo $RANDOM`
This will capture the history into a file with the date, time and a random number so multiple files will not over write each other. A typical file name looks like
28Jun23_1047_25998
I started doing this so I had a log of whatever I did with git.
I am using git-bash on a win11 system. I have used this in my .bashrc on both linux systems and recently it has stopped working. The file is created, but it is empty. If I run that command from a command line in a live shell, it works. I get a file with 500 lines, the last 500 commands run in that shell.
Is there some reason that history output doesn't go to the file when run from a noscript?
​
https://redd.it/14lgdq3
@r_bash
I have been using something the TRAP command in my .bashrc file for over 10 years to get a history of all commands run in the shell.
I have this line in my .bashrc:
trap $HOME/bin/save_history.sh EXIT
$ cat bin/save_history.sh
\#!/bin/bash
history > \~/.hist/`date +%d%b%y_%H%M_``echo $RANDOM`
This will capture the history into a file with the date, time and a random number so multiple files will not over write each other. A typical file name looks like
28Jun23_1047_25998
I started doing this so I had a log of whatever I did with git.
I am using git-bash on a win11 system. I have used this in my .bashrc on both linux systems and recently it has stopped working. The file is created, but it is empty. If I run that command from a command line in a live shell, it works. I get a file with 500 lines, the last 500 commands run in that shell.
Is there some reason that history output doesn't go to the file when run from a noscript?
​
https://redd.it/14lgdq3
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Script to make a new python virtual env and install packages into it with pip
I wrote a quick noscript to make a new python virtual env and install packages into it with pip, but only if
I tried to make it compatible with the Bourne shell and used the
## A few problems I want to ask about:
It works fine, but I couldn't:
find a way to `cd` into the new env directory and source the `env/bin/activate` from the noscript before exiting the noscript because of the noscript running in its own subshell, and I couldn't find any smart fixes for that. Although sourcing the python env from inside the noscript works as far as getting the env working and installing packages with pip inside the new env.
Another problem I faced was that using
Any feedback || tips are highly appreciated and thank you for your time.
Cheers!
## Edit:
After the tips I recieved under the post, I updated the noscript. Here it is.
https://redd.it/14kx6l8
@r_bash
I wrote a quick noscript to make a new python virtual env and install packages into it with pip, but only if
$2 $3 $4 are provided. The noscript accepts a -h flag to display a usage message (also if run without arguments). Here is the noscriptI tried to make it compatible with the Bourne shell and used the
#!/bin/sh. On Arch and derivatives, sh is symlinked to bash, so it doesn't really affect my use case, but might help others.## A few problems I want to ask about:
It works fine, but I couldn't:
find a way to `cd` into the new env directory and source the `env/bin/activate` from the noscript before exiting the noscript because of the noscript running in its own subshell, and I couldn't find any smart fixes for that. Although sourcing the python env from inside the noscript works as far as getting the env working and installing packages with pip inside the new env.
Another problem I faced was that using
echo "$PWD"/"$1" would return "$PWD"/"$1"/"$1" like /home/wolandark/env/env which didn't even exist, and that confused me a bit.Any feedback || tips are highly appreciated and thank you for your time.
Cheers!
## Edit:
After the tips I recieved under the post, I updated the noscript. Here it is.
https://redd.it/14kx6l8
@r_bash
GitHub
BASH_Scripts_For_Everyone/PyVirtEnv at main · wolandark/BASH_Scripts_For_Everyone
A collection of BASH noscripts that might benefit all *nix users - BASH_Scripts_For_Everyone/PyVirtEnv at main · wolandark/BASH_Scripts_For_Everyone
How do I copy, merge and append multiple files taking them as user inputs?
So firstly what is the difference between these and how do I do them separately?
https://redd.it/14l6jmf
@r_bash
So firstly what is the difference between these and how do I do them separately?
https://redd.it/14l6jmf
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
How should I pass "i" in the record object array in the for loop?
for i in {0..$IDs}
do
CSs=$(echo "$jsonData" | jq -r '.result.records.ChangeSetNamec')
echo "$CSs"
done
==============Below is the JSON===========
{
"status": 0,
"result": {
"records":
{
"attributes": {
"type": "agf__ADM_Work__c",
"url": "/services/data/v58.0/sobjects/agf__ADM_Work__c/a1F26000002EhXREA0"
},
"Id": "a1F26000002EhXREA0",
"Change_Set_Name__c": "W-001730"
},
{
"attributes": {
"type": "agf__ADM_Work__c",
"url": "/services/data/v58.0/sobjects/agf__ADM_Work__c/a1F26000002EwRyEAK"
},
"Id": "a1F26000002EwRyEAK",
"Change_Set_Name__c": "W-002024"
},
{
"attributes": {
"type": "agf__ADM_Work__c",
"url": "/services/data/v58.0/sobjects/agf__ADM_Work__c/a1F26000002ETgGEAW"
},
"Id": "a1F26000002ETgGEAW",
"Change_Set_Name__c": "W-001444"
}
,
"totalSize": 7,
"done": true
},
"warnings":
"The \"force data soql query\" command has been deprecated. Use \"data query\" instead.",
"The \"-u\" flag has been deprecated. Use \"--target-org | -o\" instead."
}
So I want to take the change_set of the respective ID and later then use the ID again in some SOQL query.
If i keep the statement as is i.e. "CSs=$(echo "$jsonData" | jq -r '.result.records[\].Change_Set_Name__c')" it returns all the IDs in one go, I want to iterate them one by one to perform some tasks on each ID and their changesets.
I tried using $i but seems like the '' are restricting it., it takes it as a past of the logic. Or is there any other way to iterate through the json
https://redd.it/14kehp3
@r_bash
for i in {0..$IDs}
do
CSs=$(echo "$jsonData" | jq -r '.result.records.ChangeSetNamec')
echo "$CSs"
done
==============Below is the JSON===========
{
"status": 0,
"result": {
"records":
{
"attributes": {
"type": "agf__ADM_Work__c",
"url": "/services/data/v58.0/sobjects/agf__ADM_Work__c/a1F26000002EhXREA0"
},
"Id": "a1F26000002EhXREA0",
"Change_Set_Name__c": "W-001730"
},
{
"attributes": {
"type": "agf__ADM_Work__c",
"url": "/services/data/v58.0/sobjects/agf__ADM_Work__c/a1F26000002EwRyEAK"
},
"Id": "a1F26000002EwRyEAK",
"Change_Set_Name__c": "W-002024"
},
{
"attributes": {
"type": "agf__ADM_Work__c",
"url": "/services/data/v58.0/sobjects/agf__ADM_Work__c/a1F26000002ETgGEAW"
},
"Id": "a1F26000002ETgGEAW",
"Change_Set_Name__c": "W-001444"
}
,
"totalSize": 7,
"done": true
},
"warnings":
"The \"force data soql query\" command has been deprecated. Use \"data query\" instead.",
"The \"-u\" flag has been deprecated. Use \"--target-org | -o\" instead."
}
So I want to take the change_set of the respective ID and later then use the ID again in some SOQL query.
If i keep the statement as is i.e. "CSs=$(echo "$jsonData" | jq -r '.result.records[\].Change_Set_Name__c')" it returns all the IDs in one go, I want to iterate them one by one to perform some tasks on each ID and their changesets.
I tried using $i but seems like the '' are restricting it., it takes it as a past of the logic. Or is there any other way to iterate through the json
https://redd.it/14kehp3
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Why choose these to test if the shell is broken
#!/bin/sh
#
# FFmpeg configure noscript
#
# Copyright (c) 2000-2002 Fabrice Bellard
# Copyright (c) 2005-2008 Diego Biurrun
# Copyright (c) 2005-2008 Mans Rullgard
#
# Prevent locale nonsense from breaking basic text processing.
LCALL=C
export LCALL
# make sure we are running under a compatible shell
# try to make this part work with most shells
tryexec(){
echo "Trying shell $1"
type "$1" > /dev/null 2>&1 && exec "$@"
}
unset foo
(: ${foo%%bar}) 2> /dev/null
E1="$?"
(: ${foo?}) 2> /dev/null
E2="$?"
if test "$E1" != 0 || test "$E2" = 0; then
echo "Broken shell detected. Trying alternatives."
export FFCONFEXEC
if test "0$FFCONFEXEC" -lt 1; then
FFCONFEXEC=1
tryexec bash "$0" "$@"
fi
if test "0$FFCONFEXEC" -lt 2; then
FFCONFEXEC=2
tryexec ksh "$0" "$@"
fi
if test "0$FFCONFEXEC" -lt 3; then
FFCONFEXEC=3
tryexec /usr/xpg4/bin/sh "$0" "$@"
fi
echo "No compatible shell noscript interpreter found."
echo "This configure noscript requires a POSIX-compatible shell"
echo "such as bash or ksh."
echo "THIS IS NOT A BUG IN FFMPEG, DO NOT REPORT IT AS SUCH."
echo "Instead, install a working POSIX-compatible shell."
echo "Disabling this configure test will create a broken FFmpeg."
if test "$BASHVERSION" = '2.04.0(1)-release'; then
echo "This bash version ($BASHVERSION) is broken on your platform."
echo "Upgrade to a later version if available."
fi
exit 1
fi
This is a code snippet from FFmpeg's comfigure scirpt.
It uses these to test whether the current shell is broken.
unset foo
(: ${foo%%bar}) 2> /dev/null
E1="$?"
(: ${foo?}) 2> /dev/null
E2="$?"
I understand the behaviour of these code. My question is why do they choose these? What is special about them?
https://redd.it/14k9rpz
@r_bash
#!/bin/sh
#
# FFmpeg configure noscript
#
# Copyright (c) 2000-2002 Fabrice Bellard
# Copyright (c) 2005-2008 Diego Biurrun
# Copyright (c) 2005-2008 Mans Rullgard
#
# Prevent locale nonsense from breaking basic text processing.
LCALL=C
export LCALL
# make sure we are running under a compatible shell
# try to make this part work with most shells
tryexec(){
echo "Trying shell $1"
type "$1" > /dev/null 2>&1 && exec "$@"
}
unset foo
(: ${foo%%bar}) 2> /dev/null
E1="$?"
(: ${foo?}) 2> /dev/null
E2="$?"
if test "$E1" != 0 || test "$E2" = 0; then
echo "Broken shell detected. Trying alternatives."
export FFCONFEXEC
if test "0$FFCONFEXEC" -lt 1; then
FFCONFEXEC=1
tryexec bash "$0" "$@"
fi
if test "0$FFCONFEXEC" -lt 2; then
FFCONFEXEC=2
tryexec ksh "$0" "$@"
fi
if test "0$FFCONFEXEC" -lt 3; then
FFCONFEXEC=3
tryexec /usr/xpg4/bin/sh "$0" "$@"
fi
echo "No compatible shell noscript interpreter found."
echo "This configure noscript requires a POSIX-compatible shell"
echo "such as bash or ksh."
echo "THIS IS NOT A BUG IN FFMPEG, DO NOT REPORT IT AS SUCH."
echo "Instead, install a working POSIX-compatible shell."
echo "Disabling this configure test will create a broken FFmpeg."
if test "$BASHVERSION" = '2.04.0(1)-release'; then
echo "This bash version ($BASHVERSION) is broken on your platform."
echo "Upgrade to a later version if available."
fi
exit 1
fi
This is a code snippet from FFmpeg's comfigure scirpt.
It uses these to test whether the current shell is broken.
unset foo
(: ${foo%%bar}) 2> /dev/null
E1="$?"
(: ${foo?}) 2> /dev/null
E2="$?"
I understand the behaviour of these code. My question is why do they choose these? What is special about them?
https://redd.it/14k9rpz
@r_bash
GitHub
FFmpeg/configure at master · FFmpeg/FFmpeg
Mirror of https://git.ffmpeg.org/ffmpeg.git. Contribute to FFmpeg/FFmpeg development by creating an account on GitHub.
Splitting file by unique/not-unique
I have a couple of files that look something like this:
chr1 94160888 94161133 GAGTGTCTCTCAGAGTGA 91
chr1 94160888 94161133 GTCACTGTGTCTCAGTGT 84
chr1 94160888 94161133 CACAGTCACACTCTCTCA 56
chr1 94160888 94161133 CACTCACTGAGTGTGTGA 51
chr1 94160888 94161133 GACTGAGACACTCACACT 22
chr1 94121054 94121299 CAGTCAGACAGTCAGACT 91
chr1 94121054 94121299 GACAGTGTCTCTCACTCT 76
chr1 94121054 94121299 GACAGTGTCTCTCACTCT 62
And I need to identify them by unique strings in column 4. I was hoping to split these into two separate files. However, the closest thing I've found to at least find unique values is
​
EDIT: for file simplicity
https://redd.it/14jooud
@r_bash
I have a couple of files that look something like this:
chr1 94160888 94161133 GAGTGTCTCTCAGAGTGA 91
chr1 94160888 94161133 GTCACTGTGTCTCAGTGT 84
chr1 94160888 94161133 CACAGTCACACTCTCTCA 56
chr1 94160888 94161133 CACTCACTGAGTGTGTGA 51
chr1 94160888 94161133 GACTGAGACACTCACACT 22
chr1 94121054 94121299 CAGTCAGACAGTCAGACT 91
chr1 94121054 94121299 GACAGTGTCTCTCACTCT 76
chr1 94121054 94121299 GACAGTGTCTCTCACTCT 62
And I need to identify them by unique strings in column 4. I was hoping to split these into two separate files. However, the closest thing I've found to at least find unique values is
sort -k4,4 -u, which would be fine, but it still prints the first instance of a duplicated string, which I do not want. Is there a way to print only the lines where a column 4 string appears once, and is there a way to print lines where one appears more than once?​
EDIT: for file simplicity
https://redd.it/14jooud
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Can't use wildcard * // only interpreted literally
Trying to write a back up noscript to deploy to my devices. I would like for it to prune logs as it prunes backups but am having trouble matching filenames with a wildcard.
[Whole noscript](https://hastebin.com/share/ociriwikep.bash) and [set -x output](https://hastebin.com/share/sogepemuwa.bash) available but, I 'll just paste the offending function below:
`# Remove logs of pruned backups`
`tidyLogs() {`
`mapfile -t removeList < <(grep -w "^Pruning archive" "$logFile" | awk '{ print $4 }' )`
`for ((i=0; i<${#removeList[@]}; i++)); do`
`# Slice off seconds from timestamp for matching filenames easily`
`# rm "${logFile%/"${logFile##*/}"}"/"${removeList[i]%:*}"*`
`# holder1="${logFile%/"${logFile##*/}"}"/"${removeList[i]%:*}"*`
`# eval holder2=$holder1# rm $holder2`
`set -- "${logFile%/"${logFile##*/}"}"/"${removeList[i]%:*}"*`
`rm "$*"`
`done`
`}`
It's most likely something simple but I've tried escaping and using different variations of double quotes. I moved on to the `eval` method and finally the `set` method, which I like but, it is being passed in literally no matter what I throw at it
Any advice would be appreciated
EDIT: For anyone that comes across this. It wasn't matching anything and as a last try was attempting the asterisk as literal. I missed that the backups had a hostname in them and the log files were named by timestamp only. Totally simply error.
https://redd.it/14j1ugx
@r_bash
Trying to write a back up noscript to deploy to my devices. I would like for it to prune logs as it prunes backups but am having trouble matching filenames with a wildcard.
[Whole noscript](https://hastebin.com/share/ociriwikep.bash) and [set -x output](https://hastebin.com/share/sogepemuwa.bash) available but, I 'll just paste the offending function below:
`# Remove logs of pruned backups`
`tidyLogs() {`
`mapfile -t removeList < <(grep -w "^Pruning archive" "$logFile" | awk '{ print $4 }' )`
`for ((i=0; i<${#removeList[@]}; i++)); do`
`# Slice off seconds from timestamp for matching filenames easily`
`# rm "${logFile%/"${logFile##*/}"}"/"${removeList[i]%:*}"*`
`# holder1="${logFile%/"${logFile##*/}"}"/"${removeList[i]%:*}"*`
`# eval holder2=$holder1# rm $holder2`
`set -- "${logFile%/"${logFile##*/}"}"/"${removeList[i]%:*}"*`
`rm "$*"`
`done`
`}`
It's most likely something simple but I've tried escaping and using different variations of double quotes. I moved on to the `eval` method and finally the `set` method, which I like but, it is being passed in literally no matter what I throw at it
Any advice would be appreciated
EDIT: For anyone that comes across this. It wasn't matching anything and as a last try was attempting the asterisk as literal. I missed that the backups had a hostname in them and the log files were named by timestamp only. Totally simply error.
https://redd.it/14j1ugx
@r_bash
Small collection of Bash noscripts to launch functionalities in folders
https://github.com/tanrax/bash-folders
https://redd.it/14io0q7
@r_bash
https://github.com/tanrax/bash-folders
https://redd.it/14io0q7
@r_bash
GitHub
GitHub - tanrax/bash-folders: Small collection of Bash noscripts to launch functionalities in folders when new files appear, such…
Small collection of Bash noscripts to launch functionalities in folders when new files appear, such as optimizing videos, converting images or battery management. - tanrax/bash-folders
problem in my while loop: empty output files
Hello,
​
I have this command:
awk -F'\t' '$3 ~ "Aspergillus fumigatus" {print}' $krakenfile > Aspergillusfumigatuslines.txt
It is working very fine, It just extracts every line in the file $krakenfile that contain the word "Aspergillus fumigatus" in its third column.
Now, I want to introduce another file ($fungalnames) that contains multiple lines, every line contains names of species and I want to apply the command on every line of the new file.
I tried this:
while IFS= read -r speciename
do
awk -F'\t' '$3 ~ "$speciename" {print}' $krakenfile > "${speciename}lines.txt
done < $fungalnames
Anyway, the output files are created (I had 8 species names in my $fungalnames file and there are 8 output files, every file is named to a line, but all the files are empty !!
I tried multiple times, and I changed syntaxes, but nothing is working.
I think I am escaping an important thing, can anyone help me please! Thank you in advance!
https://redd.it/14wtsdb
@r_bash
Hello,
​
I have this command:
awk -F'\t' '$3 ~ "Aspergillus fumigatus" {print}' $krakenfile > Aspergillusfumigatuslines.txt
It is working very fine, It just extracts every line in the file $krakenfile that contain the word "Aspergillus fumigatus" in its third column.
Now, I want to introduce another file ($fungalnames) that contains multiple lines, every line contains names of species and I want to apply the command on every line of the new file.
I tried this:
while IFS= read -r speciename
do
awk -F'\t' '$3 ~ "$speciename" {print}' $krakenfile > "${speciename}lines.txt
done < $fungalnames
Anyway, the output files are created (I had 8 species names in my $fungalnames file and there are 8 output files, every file is named to a line, but all the files are empty !!
I tried multiple times, and I changed syntaxes, but nothing is working.
I think I am escaping an important thing, can anyone help me please! Thank you in advance!
https://redd.it/14wtsdb
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Automatically upload files to usb when usb is plugged in
Wondering if there is a way so that when we plug in a USB it takes files from a certain directory and automatically uploads them to the USB? Does anyone have any ideas? Thank you!
https://redd.it/14wto8h
@r_bash
Wondering if there is a way so that when we plug in a USB it takes files from a certain directory and automatically uploads them to the USB? Does anyone have any ideas? Thank you!
https://redd.it/14wto8h
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
How to repeat a command with parameters swapped?
If I run a command like:
to become #536 in the command history and later I want to run the same again with parameters swapped I can do:
Is there a way to say combine the word designators without repeating the command number?
I did not find a viable delimiter or any documentation going that deep.
​
​
​
https://redd.it/14iqv5q
@r_bash
If I run a command like:
specialcmd -ab Parm1 Parm2to become #536 in the command history and later I want to run the same again with parameters swapped I can do:
!536:0-1 !536:3 !536:2Is there a way to say combine the word designators without repeating the command number?
I did not find a viable delimiter or any documentation going that deep.
​
​
​
https://redd.it/14iqv5q
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community