A way to run a noscript called XYZ.sh and the output will be in a file called XYX.out
I was asked to write a noscript that a user could run and the output would be easy for them to copy.
Although this is not what the noscript did it is an example where if you run a noscript called "AScript.sh" the user will see the output and have a noscript called "AScript.out" after.
I hope someone finds the idea useful.
https://redd.it/ytm2ud
@r_bash
I was asked to write a noscript that a user could run and the output would be easy for them to copy.
Although this is not what the noscript did it is an example where if you run a noscript called "AScript.sh" the user will see the output and have a noscript called "AScript.out" after.
I hope someone finds the idea useful.
#!/usr/bin/env bash
# Get the noscript name
Me="${0##*/}"
( (
# do a read from the df command
while read -r MountPoint Type; do
# print out a command
echo "${MountPoint} uses filesystem type ${Type}"
sleep 2
# From inside the first loop do something withn the mount point
while read -r FoundFile; do
# Print out a message
echo "I have found your file \"${FoundFile}\" in filesystem \"${MountPoint}\""
done< <(find "${MountPoint}" -xdev -type f -iname "*[a-c].mp4" 2> /dev/null)
# run a df and pass it to read
done< <(df -PTh -txfs -text{3,4} | awk '!/ilesystem/ { print $7 " " $2}')
) 2>&1 ) | tee "${Me/%sh/out}"
https://redd.it/ytm2ud
@r_bash
Bash noscript to rename files excluding names in an array
I currenlty have a noscript where I rename files by removing whitespace and certain names.
prename -v 's/ /_/g' *
prename -v 's/_-_/_/g' *
prename -v 's/_\(Summer-HD\)//ig' *
prename -v 's/_\(Hammer\)//ig' *
prename -v 's/_\(Hardware-Hybrid\)//g' *
prename -v 's/_\(digital\)//ig' *
prename -v 's/_\(Resolution-SD\)//ig' *
What I have tried is a for loop and place name in an array but that has not worked.
exclude=('(Summer-HD)' '(Hammer)' '(digital)' '(Resolution-SD)' '(Vacation)' '(Hammer-Hybrid)')
for x in "${exclude[@]}";
do prename -v 's/$x/_/g' * {} \;
done
This for loop does not work at all, and I'm not sure if I can pass a variable to prename. I would like to put the names in an array since I currently have more than 200 that i would like to remove. This list will grow as I restore these files from old backups.
https://redd.it/ytqnsb
@r_bash
I currenlty have a noscript where I rename files by removing whitespace and certain names.
prename -v 's/ /_/g' *
prename -v 's/_-_/_/g' *
prename -v 's/_\(Summer-HD\)//ig' *
prename -v 's/_\(Hammer\)//ig' *
prename -v 's/_\(Hardware-Hybrid\)//g' *
prename -v 's/_\(digital\)//ig' *
prename -v 's/_\(Resolution-SD\)//ig' *
What I have tried is a for loop and place name in an array but that has not worked.
exclude=('(Summer-HD)' '(Hammer)' '(digital)' '(Resolution-SD)' '(Vacation)' '(Hammer-Hybrid)')
for x in "${exclude[@]}";
do prename -v 's/$x/_/g' * {} \;
done
This for loop does not work at all, and I'm not sure if I can pass a variable to prename. I would like to put the names in an array since I currently have more than 200 that i would like to remove. This list will grow as I restore these files from old backups.
https://redd.it/ytqnsb
@r_bash
reddit
Bash noscript to rename files excluding names in an array
I currenlty have a noscript where I rename files by removing whitespace and certain names. prename -v 's/ /_/g' * prename -v 's/_-_/_/g'...
ASCII Pendulum written in BASH noscript
I am so excited to share my BASH ASCII graphics library.
Been working on it for a while and its finally working.
I made a ASCII pendulum using it.
I've named the library - baSHed2D
Tbh the whole logic of pendulum was copied from coding train YouTube channel's p5.js pendulum video😅
Here's the Demo Video
YouTube link
Ans here's the code
GitHub link
Please review my code and suggestions are welcomed and I actually need some suggestions to improve this.
What you can do using baSHed2D
Draw lines,
Draw circles,
Draw rectangle,
Move these shapes
I will add mouse location getters too.
And a huge thanks to you guys, i had some issues regarding my code and I posted it here. It was for the line drawing algorithm, you guys are great. I learnt so much from your advices.
https://redd.it/ytriej
@r_bash
I am so excited to share my BASH ASCII graphics library.
Been working on it for a while and its finally working.
I made a ASCII pendulum using it.
I've named the library - baSHed2D
Tbh the whole logic of pendulum was copied from coding train YouTube channel's p5.js pendulum video😅
Here's the Demo Video
YouTube link
Ans here's the code
GitHub link
Please review my code and suggestions are welcomed and I actually need some suggestions to improve this.
What you can do using baSHed2D
Draw lines,
Draw circles,
Draw rectangle,
Move these shapes
I will add mouse location getters too.
And a huge thanks to you guys, i had some issues regarding my code and I posted it here. It was for the line drawing algorithm, you guys are great. I learnt so much from your advices.
https://redd.it/ytriej
@r_bash
YouTube
ASCII Pendulum | BASH Script | baSHed2D
Code : https://github.com/adi3120/baSHed2D/blob/main/game.sh
Correct way to insert text in columns
I have this Columns in a text file.
Lets say i would like to add a column to Countries or Numbers or Cities.
What would be the correct way to do this?
I've tried this, to insert in the second column.
printf '%-20s' 'Stockholm' | paste -d "\\t" /file.txt -
Numbers Cities Countries
232323 blahblah waeawewae
232323 blahdadad waeawewaew
123123 asdsadads waewaewaea
123123 asdasdasd waeaweawea
​
https://redd.it/ytw075
@r_bash
I have this Columns in a text file.
Lets say i would like to add a column to Countries or Numbers or Cities.
What would be the correct way to do this?
I've tried this, to insert in the second column.
printf '%-20s' 'Stockholm' | paste -d "\\t" /file.txt -
Numbers Cities Countries
232323 blahblah waeawewae
232323 blahdadad waeawewaew
123123 asdsadads waewaewaea
123123 asdasdasd waeaweawea
​
https://redd.it/ytw075
@r_bash
reddit
Correct way to insert text in columns
I have this Columns in a text file. Lets say i would like to add a column to Countries or Numbers or Cities. What would be the correct way to do...
Running bash noscript from outside Terminal, won't pick up second flag ¯\_(ツ)_/¯
Hi,
I'm running a noscript from Lingon X, a scheduler on macos. It generally works but ignores the *--cuesheet* flag. Can anyone see why?
Lingon X uses this command:
/bin/bash -li /Users/goggle-moggle/iplayer.sh
The iplayer.sh noscript looks like this:
#!/bin/bash
shopt -s expand_aliases
alias gip='get_iplayer --file-prefix="<name> - <episode> <pid> <version>" --pid '
gip m000b075 --pid-recursive --cuesheet
gip b09ymqm4 --pid-recursive --cuesheet
The noscript works as expected when I run from Terminal.
Thanks!
https://redd.it/ytwsi0
@r_bash
Hi,
I'm running a noscript from Lingon X, a scheduler on macos. It generally works but ignores the *--cuesheet* flag. Can anyone see why?
Lingon X uses this command:
/bin/bash -li /Users/goggle-moggle/iplayer.sh
The iplayer.sh noscript looks like this:
#!/bin/bash
shopt -s expand_aliases
alias gip='get_iplayer --file-prefix="<name> - <episode> <pid> <version>" --pid '
gip m000b075 --pid-recursive --cuesheet
gip b09ymqm4 --pid-recursive --cuesheet
The noscript works as expected when I run from Terminal.
Thanks!
https://redd.it/ytwsi0
@r_bash
reddit
Running bash noscript from outside Terminal, won't pick up second...
Hi, I'm running a noscript from Lingon X, a scheduler on macos. It generally works but ignores the *--cuesheet* flag. Can anyone see why? Lingon X...
Round robin algorithm in bash noscript
Hi everyone. So I just started learning bash noscript a few weeks ago. I got an assignment and I have no idea how to do this. I kinda wrote in C# but I dont know how to write in bash. Can anyone help? below is the prompt
Provide a detailed specification, and design of the bash noscript that will emulate the behaviour of the round robin scheduling algorithm
https://redd.it/ytyxak
@r_bash
Hi everyone. So I just started learning bash noscript a few weeks ago. I got an assignment and I have no idea how to do this. I kinda wrote in C# but I dont know how to write in bash. Can anyone help? below is the prompt
Provide a detailed specification, and design of the bash noscript that will emulate the behaviour of the round robin scheduling algorithm
https://redd.it/ytyxak
@r_bash
reddit
Round robin algorithm in bash noscript
Hi everyone. So I just started learning bash noscript a few weeks ago. I got an assignment and I have no idea how to do this. I kinda wrote in C#...
Check if executable has a live process
How to write a bash noscript which checks periodically specific executable has a live process. Say call it as ./check executable_name
https://redd.it/yu8xvc
@r_bash
How to write a bash noscript which checks periodically specific executable has a live process. Say call it as ./check executable_name
https://redd.it/yu8xvc
@r_bash
reddit
Check if executable has a live process
How to write a bash noscript which checks periodically specific executable has a live process. Say call it as ./check [executable_name]
Scripting Issue - new to noscripting
I'm trying to create a noscript that uses one argument, and only one argument. This argument specifies the number of minutes to count down. It should start with the number of minutes, then count down second by second writing the text "there are x seconds remaining". When there is no time left the noscript should echo "time is over" and then quit.
So far I have this:
!#/bin/bash
for (( COUNTER=$1; COUNTER>0; COUNTER-- )); do sleep 1
echo "there are $COUNTER seconds remaining"
done
echo "time is over"
exit 0
​
​
This noscript counts down by the second if I run "bash noscript 5" it will count down 5 seconds, but I need it to count down 5 minutes, second by second when I do that. Appreciate all help
https://redd.it/yueqeh
@r_bash
I'm trying to create a noscript that uses one argument, and only one argument. This argument specifies the number of minutes to count down. It should start with the number of minutes, then count down second by second writing the text "there are x seconds remaining". When there is no time left the noscript should echo "time is over" and then quit.
So far I have this:
!#/bin/bash
for (( COUNTER=$1; COUNTER>0; COUNTER-- )); do sleep 1
echo "there are $COUNTER seconds remaining"
done
echo "time is over"
exit 0
​
​
This noscript counts down by the second if I run "bash noscript 5" it will count down 5 seconds, but I need it to count down 5 minutes, second by second when I do that. Appreciate all help
https://redd.it/yueqeh
@r_bash
reddit
Scripting Issue - new to noscripting
I'm trying to create a noscript that uses one argument, and only one argument. This argument specifies the number of minutes to count down. It...
The most secret and vital piece of kit for the ongoing war between my friend and I.
\#!/bin/bash
​
rootvegatable='potato'
rootvegatable='cabbage'
rootvegatable='carrot'
rootvegatable='turnip'
echo"your quest to find out your destiny is nigh at hand"
sleep 3
echo"Lucy we have used are arcane arts"
sleep 3
echo"some of our most arcane secrets and sacred rights have been used to reveal the truth of your destiny"
sleep 3
echo "the spirits have spoken and your destiny is is that of the noble %$RANDOM$rootvegatable
​
​
It's the last line that tripping me up how do I make it choose a random variable?
https://redd.it/yuarsa
@r_bash
\#!/bin/bash
​
rootvegatable='potato'
rootvegatable='cabbage'
rootvegatable='carrot'
rootvegatable='turnip'
echo"your quest to find out your destiny is nigh at hand"
sleep 3
echo"Lucy we have used are arcane arts"
sleep 3
echo"some of our most arcane secrets and sacred rights have been used to reveal the truth of your destiny"
sleep 3
echo "the spirits have spoken and your destiny is is that of the noble %$RANDOM$rootvegatable
​
​
It's the last line that tripping me up how do I make it choose a random variable?
https://redd.it/yuarsa
@r_bash
reddit
The most secret and vital piece of kit for the ongoing war between...
\#!/bin/bash rootvegatable='potato' rootvegatable='cabbage' rootvegatable='carrot' rootvegatable='turnip' echo"your quest to find...
What is the underscore variable in bash, that always is set to my last issued command?
When executing
# env
SHELL=/usr/local/bin/bash
LESSHISTFILE=-
XPCFLAGS=0x0
HISTCONTROL=ignorespace:ignoredups:erasedups
HISTIGNORE=&;???;*sudo -S*
...
BLOCKSIZE=1024
=/usr/bin/env <----------------- here!
I wonder what this is called (as in: how to google for it for more details) and if I could make use of it (besides the usual ways to recall the last command[s\] from history with
Thanks in advance!
FWIW: bash 5.2.9, but it has been there since ... forever?
https://redd.it/yv274j
@r_bash
When executing
env, I'll see a set of variables, including one that is (named) the underscore '_' which has my last command. eg:# env
SHELL=/usr/local/bin/bash
LESSHISTFILE=-
XPCFLAGS=0x0
HISTCONTROL=ignorespace:ignoredups:erasedups
HISTIGNORE=&;???;*sudo -S*
...
BLOCKSIZE=1024
=/usr/bin/env <----------------- here!
I wonder what this is called (as in: how to google for it for more details) and if I could make use of it (besides the usual ways to recall the last command[s\] from history with
!$ !! !-2 etc.).Thanks in advance!
FWIW: bash 5.2.9, but it has been there since ... forever?
https://redd.it/yv274j
@r_bash
reddit
What is the underscore variable in bash, that always is set to my...
When executing `env`, I'll see a set of variables, including one that is (named) the underscore '`_`' which has my last command. eg: # env ...
How do I make my prompt show the directory string only in the current line?
https://redd.it/yv5ozd
@r_bash
https://redd.it/yv5ozd
@r_bash
What are some resources for markup/prettifying bash commands for presentations?
I have the following bash noscript which runs
I have tried to use editors like https://carbon.now.sh/
but they all show something like
https://preview.redd.it/ofv5i8qzpyz91.png?width=1380&format=png&auto=webp&s=e7c4555f0db1503667c967d0fed0a45e38ea7410
where the
https://redd.it/yv8qqj
@r_bash
I have the following bash noscript which runs
python3:python3 /dir/to/python_code.py --option1 param1 --option2 param2I have tried to use editors like https://carbon.now.sh/
but they all show something like
https://preview.redd.it/ofv5i8qzpyz91.png?width=1380&format=png&auto=webp&s=e7c4555f0db1503667c967d0fed0a45e38ea7410
where the
python3 bit is colored, but nothing else. I am hoping to get more coloring, especially in the options. Is there an alternative editor that can do that? Thanks.https://redd.it/yv8qqj
@r_bash
carbon.now.sh
Carbon is the easiest way to create and share beautiful images of your source code.
Print pattern match once line below was found
I've got a really annoying problem. In my text file I have a number of objects that relate to an object group. An example is below.
object-group network TEST-GROUP1
network-object object SERVER1
network-object object SERVER2
network-object object SERVER3
network-object object SERVER4
The number of objects inside of any object-group can vary. What I need to do is check what object-groups, my object is a part of. So for example, how would I find if SERVER3 was part of an object group, and if it was, print that object group it's a member of.
Note, SERVER3 may be part of many object groups.
https://redd.it/yvcl79
@r_bash
I've got a really annoying problem. In my text file I have a number of objects that relate to an object group. An example is below.
object-group network TEST-GROUP1
network-object object SERVER1
network-object object SERVER2
network-object object SERVER3
network-object object SERVER4
The number of objects inside of any object-group can vary. What I need to do is check what object-groups, my object is a part of. So for example, how would I find if SERVER3 was part of an object group, and if it was, print that object group it's a member of.
Note, SERVER3 may be part of many object groups.
https://redd.it/yvcl79
@r_bash
Execute command for new files in directory tree
I currently have a noscript that uses fswatch to detect new files in a directory tree. In general it seems to work fine and I'm now trying to make the process more resilient. I'm looking for ways to handle the case where the watch noscript isn't running and a new file is added before the watch noscript is restarted. What are my options for this scenario?
https://redd.it/yvf58k
@r_bash
I currently have a noscript that uses fswatch to detect new files in a directory tree. In general it seems to work fine and I'm now trying to make the process more resilient. I'm looking for ways to handle the case where the watch noscript isn't running and a new file is added before the watch noscript is restarted. What are my options for this scenario?
https://redd.it/yvf58k
@r_bash
reddit
Execute command for new files in directory tree
I currently have a noscript that uses fswatch to detect new files in a directory tree. In general it seems to work fine and I'm now trying to make...
fill 2d array with spaces
I have a 2d array called canvas.
I want to fill this array with spaces.
Heres my code
#! /bin/bash
declare -A canvas
rows=30
cols=40
createCanvas() {
for ((i = 0; i < $rows; i++)); do
for ((j = 0; j < $cols; j++)); do
canvas$i, $j="."
done
done
}
drawCanvas() {
for ((i = 0; i < $rows; i++)); do
str=()
for ((j = 0; j < $cols; j++)); do
str+="${canvas$i, $j} "
done
echo $str
done
}
drawPointCustom() {
local x=$1
local y=$2
local c=$3
canvas"$x", "$y"=$c
}
createCanvas
drawPointCustom 10 10 'A'
drawCanvas
the create canvas is where im filling my array with '.' dots. But i want to fill it with spaces so that when i display it, nothing is visible. but when i try this
createCanvas() {
for ((i = 0; i < $rows; i++)); do
for ((j = 0; j < $cols; j++)); do
canvas$i, $j=" "
done
done
}
Everything becomes wrong.
my drawpointCustom function fails to work properly. Please help
​
Thanks in advance. :)
https://redd.it/yvtnah
@r_bash
I have a 2d array called canvas.
I want to fill this array with spaces.
Heres my code
#! /bin/bash
declare -A canvas
rows=30
cols=40
createCanvas() {
for ((i = 0; i < $rows; i++)); do
for ((j = 0; j < $cols; j++)); do
canvas$i, $j="."
done
done
}
drawCanvas() {
for ((i = 0; i < $rows; i++)); do
str=()
for ((j = 0; j < $cols; j++)); do
str+="${canvas$i, $j} "
done
echo $str
done
}
drawPointCustom() {
local x=$1
local y=$2
local c=$3
canvas"$x", "$y"=$c
}
createCanvas
drawPointCustom 10 10 'A'
drawCanvas
the create canvas is where im filling my array with '.' dots. But i want to fill it with spaces so that when i display it, nothing is visible. but when i try this
createCanvas() {
for ((i = 0; i < $rows; i++)); do
for ((j = 0; j < $cols; j++)); do
canvas$i, $j=" "
done
done
}
Everything becomes wrong.
my drawpointCustom function fails to work properly. Please help
​
Thanks in advance. :)
https://redd.it/yvtnah
@r_bash
reddit
fill 2d array with spaces
I have a 2d array called canvas. I want to fill this array with spaces. Heres my code #! /bin/bash declare -A canvas ...
Question about sort
In a file with two columns (think Name and Surname, for example), is doing
If I do both commands they appear to give the same output, however, in a one-liner that calculates the "average number of surnames per name" (not really what I'm doing but it's analogous) I get different results.
For clarity, imagine I have the following file:
Michael Jackson
Michael Scott
Michael Schumacher
Peter Griffin
Peter Pan
Someother Guy
Here,
Back to my question now, in my use case I have to remove the duplicates, so I'm doing this:
gawk 'NR>1{print $13, $2}' file.txt | sort | uniq | gawk '{print $1}' | uniq -c | gawk '{total += $1}END{print total/NR}'
The result of this is 1.99948.
However, when I do this:
gawk 'NR>1{print $13, $2}' dm6.txt | sort -k1,1 -k2,2 | uniq | gawk '{print $1}' | uniq -c | gawk '{total += $1}END{print total/NR}'
The result is 2.002.
So my question is, why is the result different if both commands do the same thing (or at least it looks like that when I examine the outputs), and if they don't do the same thing, what is the difference and which one do you think I should use?
https://redd.it/yw2lli
@r_bash
In a file with two columns (think Name and Surname, for example), is doing
sort and sort -k1,1 -k2,2 the same?If I do both commands they appear to give the same output, however, in a one-liner that calculates the "average number of surnames per name" (not really what I'm doing but it's analogous) I get different results.
For clarity, imagine I have the following file:
Michael Jackson
Michael Scott
Michael Schumacher
Peter Griffin
Peter Pan
Someother Guy
Here,
Michael has 3 different surnames, Peter has 2 and Someother has 1, so the average surnames per name is 2.Back to my question now, in my use case I have to remove the duplicates, so I'm doing this:
gawk 'NR>1{print $13, $2}' file.txt | sort | uniq | gawk '{print $1}' | uniq -c | gawk '{total += $1}END{print total/NR}'
The result of this is 1.99948.
However, when I do this:
gawk 'NR>1{print $13, $2}' dm6.txt | sort -k1,1 -k2,2 | uniq | gawk '{print $1}' | uniq -c | gawk '{total += $1}END{print total/NR}'
The result is 2.002.
So my question is, why is the result different if both commands do the same thing (or at least it looks like that when I examine the outputs), and if they don't do the same thing, what is the difference and which one do you think I should use?
https://redd.it/yw2lli
@r_bash
reddit
Question about sort
In a file with two columns (think Name and Surname, for example), is doing `sort` and `sort -k1,1 -k2,2` the same? If I do both commands they...
Help with Changing JDK via Mac Terminal
Hey all,
I think in the scheme of this sub this is probably a fairly simple request but I'm not familiar with Bash noscripting at all and hoping someone can help me here.
​
I had a noscript configured for me in my \~/.Bash\_profile on my Macbook by a colleague to allow me to change my Java JDK at will.
​
I went to run this today (possibly of note, after installing Ventura?) and today can't get it to run, it should, in theory, change JDK Using 'JDK XX' (XX being the version number) however as of today I get zsh command not found.
​
I get the impression this is probably something to do with the OS upgrade but can't figure out what. ANy advice would be very gratefully received.
​
export JAVA_HOME=/Library/Java/JavaVirtualMachines/temurin-17.jdk/Contents/Home
jdk() {
version=$1
export JAVA_HOME=$(/usr/libexec/java_home -v"$version");
java -version
}
https://redd.it/yw55rf
@r_bash
Hey all,
I think in the scheme of this sub this is probably a fairly simple request but I'm not familiar with Bash noscripting at all and hoping someone can help me here.
​
I had a noscript configured for me in my \~/.Bash\_profile on my Macbook by a colleague to allow me to change my Java JDK at will.
​
I went to run this today (possibly of note, after installing Ventura?) and today can't get it to run, it should, in theory, change JDK Using 'JDK XX' (XX being the version number) however as of today I get zsh command not found.
​
I get the impression this is probably something to do with the OS upgrade but can't figure out what. ANy advice would be very gratefully received.
​
export JAVA_HOME=/Library/Java/JavaVirtualMachines/temurin-17.jdk/Contents/Home
jdk() {
version=$1
export JAVA_HOME=$(/usr/libexec/java_home -v"$version");
java -version
}
https://redd.it/yw55rf
@r_bash
reddit
Help with Changing JDK via Mac Terminal
Hey all, I think in the scheme of this sub this is probably a fairly simple request but I'm not familiar with Bash noscripting at all and hoping...
Replace text in given column only
Hi all - I have a csv file separated by commas , am looking to find and replace in column 4 only, the last string which will be like /something* or with .git
Therefor name/age/postcode should become name/age. git
Looking at awk sed tr for solutions but this is a bit complex for me
https://redd.it/yw6jg6
@r_bash
Hi all - I have a csv file separated by commas , am looking to find and replace in column 4 only, the last string which will be like /something* or with .git
Therefor name/age/postcode should become name/age. git
Looking at awk sed tr for solutions but this is a bit complex for me
https://redd.it/yw6jg6
@r_bash
reddit
Replace text in given column only
Hi all - I have a csv file separated by commas , am looking to find and replace in column 4 only, the last string which will be like /something*...