Need Help with Removing Files Using Bash Script
​
For some reason, this removes the bash_file when I run bash_file itself.
I'm trying to remove files in a directory that have a size of zero. I'm not sure why it doesn't work properly.
https://redd.it/17kagkx
@r_bash
if [[ $# -eq 0 ]]; then # if user doesn't enter anything, default to pwddir=$(pwd)elif [[ -d "$1" ]]; then #if the user enters a directory that exists assign to dirdir=$1elseecho "usage: bash_file.sh <directory>" #otherwise, tell the user to enter a valid directoryexit 1 # exit programfi​
for x in "$dir"/*; do #goes through and finds the files of size 0if [[ -s "$x" ]]; thenrm "$x"fidoneFor some reason, this removes the bash_file when I run bash_file itself.
I'm trying to remove files in a directory that have a size of zero. I'm not sure why it doesn't work properly.
https://redd.it/17kagkx
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Minimalistic Bash noscript to fuzzy search and open chrome bookmarks from cli
Hello bash fellows,
I was a bit annoyed by reopening my frequently used bookmarks in Chrome. I added an extension called Quickmarks but don't like it that much. I want to be faster. And I want to have fuzzy search.
Hence, I decided to create a noscript that fetches all my bookmarks from the file system and opens a fuzzy search session on the bookmark noscripts. On selection, it opens the related url in Chrome.
https://preview.redd.it/27veeg13pixb1.png?width=2002&format=png&auto=webp&s=01c3597ecbb7e8a981fae8723c44c9250fc2a600
It works pretty well. What do you think? What is your workaround for this?
Link to the noscript 👉 https://github.com/fynnfluegge/mydotfiles/blob/main/.noscripts/fzfbookmarks.sh
https://redd.it/17ki4lp
@r_bash
Hello bash fellows,
I was a bit annoyed by reopening my frequently used bookmarks in Chrome. I added an extension called Quickmarks but don't like it that much. I want to be faster. And I want to have fuzzy search.
Hence, I decided to create a noscript that fetches all my bookmarks from the file system and opens a fuzzy search session on the bookmark noscripts. On selection, it opens the related url in Chrome.
https://preview.redd.it/27veeg13pixb1.png?width=2002&format=png&auto=webp&s=01c3597ecbb7e8a981fae8723c44c9250fc2a600
It works pretty well. What do you think? What is your workaround for this?
Link to the noscript 👉 https://github.com/fynnfluegge/mydotfiles/blob/main/.noscripts/fzfbookmarks.sh
https://redd.it/17ki4lp
@r_bash
Custom waybar module for controlling gamma
Howdy folks! I'm very new to bash noscripting and just wrote a couple noscripts to control the temperature of my laptop's display from my bar. I wanted to put this somewhere in case it was useful to someone or there was a better way to do it. Right now there are a couple values that I want to be stored between instances of the noscripts and I'm doing it in files. I wonder if there's a better way to do this that doesn't require the full absolute path of the files? Like if I can refer to the noscript's location in the file system?
Sorry if this question is super noobish, even a project this simple that's just a wrapper around someone else's code wasn't easy for me! So I appreciate any help I can get.
https://github.com/frolickingpotato/waybar-gammastep/blob/main/README.md
https://redd.it/17kqxsy
@r_bash
Howdy folks! I'm very new to bash noscripting and just wrote a couple noscripts to control the temperature of my laptop's display from my bar. I wanted to put this somewhere in case it was useful to someone or there was a better way to do it. Right now there are a couple values that I want to be stored between instances of the noscripts and I'm doing it in files. I wonder if there's a better way to do this that doesn't require the full absolute path of the files? Like if I can refer to the noscript's location in the file system?
Sorry if this question is super noobish, even a project this simple that's just a wrapper around someone else's code wasn't easy for me! So I appreciate any help I can get.
https://github.com/frolickingpotato/waybar-gammastep/blob/main/README.md
https://redd.it/17kqxsy
@r_bash
GitHub
waybar-gammastep/README.md at main · frolickingpotato/waybar-gammastep
A gammastep control module for waybar. Contribute to frolickingpotato/waybar-gammastep development by creating an account on GitHub.
Help creating shell noscript for removing embedded subnoscripts from video files
I have a series of video lessons and part of the software leverages an AI assistant to automatically create and embed subnoscripts to the spoken parts. These subnoscripts are not captured and translated perfectly, so I'd like to be able to proofread and update these text files manually.
I have a file (queue.txt) where I list the full path to the video file, such as this:
/Volumes/Lessons/101/lesson1.mkv
/Volumes/Lessons/101/lesson2.mkv
/Volumes/Lessons/101/lesson3.mkv
I'd like to be able to run a shell noscript which takes this list of files and runs the following command against it:
mkvmerge -o <outputfilename> -S <inputfilepath>
The hope is that it outputs the following files in my current directory like this:
lesson1.mkv
lesson2.mkv
lesson3.mkv
Thanks so much in advance. This is not my area of expertise but I have a very large number of video lessons that I'm trying to make available for these students and ensure that subnoscripts are available for accessibility reasons.
https://redd.it/17krvyj
@r_bash
I have a series of video lessons and part of the software leverages an AI assistant to automatically create and embed subnoscripts to the spoken parts. These subnoscripts are not captured and translated perfectly, so I'd like to be able to proofread and update these text files manually.
I have a file (queue.txt) where I list the full path to the video file, such as this:
/Volumes/Lessons/101/lesson1.mkv
/Volumes/Lessons/101/lesson2.mkv
/Volumes/Lessons/101/lesson3.mkv
I'd like to be able to run a shell noscript which takes this list of files and runs the following command against it:
mkvmerge -o <outputfilename> -S <inputfilepath>
The hope is that it outputs the following files in my current directory like this:
lesson1.mkv
lesson2.mkv
lesson3.mkv
Thanks so much in advance. This is not my area of expertise but I have a very large number of video lessons that I'm trying to make available for these students and ensure that subnoscripts are available for accessibility reasons.
https://redd.it/17krvyj
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Sed noscripting help
I want to modify paths explicitly written in files to remove one case of ../
For example:
Somedir/../../hw
Somedir/../../../sw
now becomes after using the sed
Somedir/../hw
Somedir/../../sw
I know for certain the ../ will be in between a known directory name (Somedir in this ex) and a folder with some name (hw and sw in this ex).
Please help anyone with this.
https://redd.it/17l3qjn
@r_bash
I want to modify paths explicitly written in files to remove one case of ../
For example:
Somedir/../../hw
Somedir/../../../sw
now becomes after using the sed
Somedir/../hw
Somedir/../../sw
I know for certain the ../ will be in between a known directory name (Somedir in this ex) and a folder with some name (hw and sw in this ex).
Please help anyone with this.
https://redd.it/17l3qjn
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Sed How to uncomment two lines in a file
Let's say I have a very long configuration file, and in it there's the following lines:
What is the Sed command that will uncomment those lines, so that the output will be:
https://redd.it/17l6cc2
@r_bash
Let's say I have a very long configuration file, and in it there's the following lines:
/etc/animals.conf
-----------------
#[cats]
#Include = /etc/cats.d/listofcats
What is the Sed command that will uncomment those lines, so that the output will be:
/etc/animals.conf
-----------------
[cats]
Include = /etc/cats.d/listofcats
https://redd.it/17l6cc2
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Minimalistic Bash noscript to fuzzy search and open chrome bookmarks from cli
Hello bash fellows,
I was a bit annoyed by reopening my frequently used bookmarks in Chrome. I added an extension called Quickmarks but don't like it that much. I want to be faster. And I want to have fuzzy search.
Hence, I decided to create a noscript that fetches all my bookmarks from the file system and opens a fuzzy search session on the bookmark noscripts. On selection, it opens the related url in Chrome.
https://preview.redd.it/b8lshwkl5pxb1.png?width=2002&format=png&auto=webp&s=f384841958dd466c45ac468c77d7707f30f2ff66
It works pretty well. What do you think? What is your workaround for this?
Link to the noscript 👉 https://github.com/fynnfluegge/mydotfiles/blob/main/.noscripts/fzfbookmarks.sh
https://redd.it/17l7gzt
@r_bash
Hello bash fellows,
I was a bit annoyed by reopening my frequently used bookmarks in Chrome. I added an extension called Quickmarks but don't like it that much. I want to be faster. And I want to have fuzzy search.
Hence, I decided to create a noscript that fetches all my bookmarks from the file system and opens a fuzzy search session on the bookmark noscripts. On selection, it opens the related url in Chrome.
https://preview.redd.it/b8lshwkl5pxb1.png?width=2002&format=png&auto=webp&s=f384841958dd466c45ac468c77d7707f30f2ff66
It works pretty well. What do you think? What is your workaround for this?
Link to the noscript 👉 https://github.com/fynnfluegge/mydotfiles/blob/main/.noscripts/fzfbookmarks.sh
https://redd.it/17l7gzt
@r_bash
Script doesnt fully work
Hello guys
So because of the recent decision of youtube making people not be able to watch ad-free videos with adblocker extension, I wanted to create an noscript so that I can watch videos with mpv. The issue I have with mpv is that the it doesnt buffer fast enough for me. So I wanted to combine yt-dlp with mpv.
Now my noscript is ready but it has an issue. It works when I run each command from the noscript on my own with the terminal. But when running the noscript via bash y.bash, it doesnt perform the last command.
This is my noscript:
url=$(xsel -bo)
filename=$(shuf -i 1-10000000 -n 1)
fileextension="webm"
yt-dlp -o - "$url" | mpv --input-ipc-server=/tmp/mpvsocket - &
yt-dlp -o "/home/reddituser/Downloads/yt-dlp/$filename.$fileextension" "$url" && fullname="/home/reddituser/Downloads/yt-dlp/${filename}.${fileextension}"
timestamp=\"$(echo '{ "command": "get_property", "time-pos" }' | socat - /tmp/mpvsocket | jq -r '.data' | awk '{printf "%.6f\n", $1}')\"
echo $timestamp
echo '{ "command": "loadfile", "'"$fullname"'" }' | socat - /tmp/mpvsocket
echo "{ \"command\": \"set\", \"time-pos\", $timestamp }" | socat - /tmp/mpvsocket
The is the last command, that doesnt work
echo "{ \"command\": \"set\", \"time-pos\", $timestamp }" | socat - /tmp/mpvsocket
This is how the noscript works:
1. variable "$url" is set to the value of clipboard
2. generate random filename
3. set webm as file extension
4. download (from $url) temporarily a 720p video with yt-dlp and directly pipe it to mpv, mpv directly plays the 720p video, also uses IPC so that I can get some values, make it run in the background with "&"
5. Download a high quality version (from $url), and save it to my location with the filename being $filename.$fileextension, wait until done and then set the variable $fullname for the fullpath&fullname
6. Value of $timestamp equals the current timestamp of the 720p video playing, example \\"RANDOM_FLOATIANG_POINT\\" or \\"23.23953\\"
7. Yes It needs to be escaped with \\"
8. replace the current 720p video playing with the new high resolution downloaded video
9. Set the timestamp for the high resolution video to the one of 720p had right before it got replaced
Now the issue is command 9 doesnt work.
I get this error: {"request_id":0,"error":"error running command"}
The reason for this noscript is to directly watch the youtube video and replace it as soon as possible with a high resolution one that got downloaded, this way I can seek very fast without buffering and I am not anymore reliant on youtube.
​
https://redd.it/17lr9m5
@r_bash
Hello guys
So because of the recent decision of youtube making people not be able to watch ad-free videos with adblocker extension, I wanted to create an noscript so that I can watch videos with mpv. The issue I have with mpv is that the it doesnt buffer fast enough for me. So I wanted to combine yt-dlp with mpv.
Now my noscript is ready but it has an issue. It works when I run each command from the noscript on my own with the terminal. But when running the noscript via bash y.bash, it doesnt perform the last command.
This is my noscript:
url=$(xsel -bo)
filename=$(shuf -i 1-10000000 -n 1)
fileextension="webm"
yt-dlp -o - "$url" | mpv --input-ipc-server=/tmp/mpvsocket - &
yt-dlp -o "/home/reddituser/Downloads/yt-dlp/$filename.$fileextension" "$url" && fullname="/home/reddituser/Downloads/yt-dlp/${filename}.${fileextension}"
timestamp=\"$(echo '{ "command": "get_property", "time-pos" }' | socat - /tmp/mpvsocket | jq -r '.data' | awk '{printf "%.6f\n", $1}')\"
echo $timestamp
echo '{ "command": "loadfile", "'"$fullname"'" }' | socat - /tmp/mpvsocket
echo "{ \"command\": \"set\", \"time-pos\", $timestamp }" | socat - /tmp/mpvsocket
The is the last command, that doesnt work
echo "{ \"command\": \"set\", \"time-pos\", $timestamp }" | socat - /tmp/mpvsocket
This is how the noscript works:
1. variable "$url" is set to the value of clipboard
2. generate random filename
3. set webm as file extension
4. download (from $url) temporarily a 720p video with yt-dlp and directly pipe it to mpv, mpv directly plays the 720p video, also uses IPC so that I can get some values, make it run in the background with "&"
5. Download a high quality version (from $url), and save it to my location with the filename being $filename.$fileextension, wait until done and then set the variable $fullname for the fullpath&fullname
6. Value of $timestamp equals the current timestamp of the 720p video playing, example \\"RANDOM_FLOATIANG_POINT\\" or \\"23.23953\\"
7. Yes It needs to be escaped with \\"
8. replace the current 720p video playing with the new high resolution downloaded video
9. Set the timestamp for the high resolution video to the one of 720p had right before it got replaced
Now the issue is command 9 doesnt work.
I get this error: {"request_id":0,"error":"error running command"}
The reason for this noscript is to directly watch the youtube video and replace it as soon as possible with a high resolution one that got downloaded, this way I can seek very fast without buffering and I am not anymore reliant on youtube.
​
https://redd.it/17lr9m5
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
unexpected bash code behavior: won't total up numbers
I'm having trouble understanding why the bash program exits when the user enters integers.
total=0 # keeps track of the running total
# while the number of arguments isn't zero
# and the argument is an integer,
# add to the integer to the running total
# move to the next argument and check
# it against the req's (i.e. integer?)
while [ $# -gt 0 && $1 =~ ^-?[0-9+$ ]]; do
total=$((total + $1))
shift
done
# if the user entered something other than an
# integer or entered nothing at all
# display the error message "this program...."
if ! [ $1 =~ ^-?[0-9+$]]; then
echo "program only accepts integers"
echo "usage: $0 integer 1 integer 2 ... integer x"
exit
fi
# lastly, display the total
echo $total
I can't spot the error...
https://redd.it/17lsfnf
@r_bash
I'm having trouble understanding why the bash program exits when the user enters integers.
total=0 # keeps track of the running total
# while the number of arguments isn't zero
# and the argument is an integer,
# add to the integer to the running total
# move to the next argument and check
# it against the req's (i.e. integer?)
while [ $# -gt 0 && $1 =~ ^-?[0-9+$ ]]; do
total=$((total + $1))
shift
done
# if the user entered something other than an
# integer or entered nothing at all
# display the error message "this program...."
if ! [ $1 =~ ^-?[0-9+$]]; then
echo "program only accepts integers"
echo "usage: $0 integer 1 integer 2 ... integer x"
exit
fi
# lastly, display the total
echo $total
I can't spot the error...
https://redd.it/17lsfnf
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
TIL bash -c takes up to 2 arguments
I expected
On the other hand
In man page I found this:
-c
If the -c option is present, then commands are read from the
first non-option argument commandstring. **If there are arguments after the commandstring, the first argument is assigned
to $0 and any remaining arguments are assigned to the positional parameters. The assignment to $0 sets the name of the
shell, which is used in warning and error messages.
Did you know this?
https://redd.it/17lxfr9
@r_bash
I expected
bash -c 'echo "[$@]"' 10 20 30 to print 10 20 30 but surprisingly it only showed 20 30.On the other hand
bash -c 'echo "[$0 $@]"' 10 20 30 prints 10 20 30.In man page I found this:
-c
If the -c option is present, then commands are read from the
first non-option argument commandstring. **If there are arguments after the commandstring, the first argument is assigned
to $0 and any remaining arguments are assigned to the positional parameters. The assignment to $0 sets the name of the
shell, which is used in warning and error messages.
Did you know this?
https://redd.it/17lxfr9
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Troubles when quoting grep statement for array
Hey all!
The idea is to get an array of space-separated colors from a global config file. This works but shellcheck keeps complaining about the $1 var not being quoted. However when I single quote it the variable isn't expanded.
I'm sure I'm missing something obvious but as I'm quite new to this I'm struggling to see what.
I hope someone can help!
https://redd.it/17m9bjb
@r_bash
Hey all!
The idea is to get an array of space-separated colors from a global config file. This works but shellcheck keeps complaining about the $1 var not being quoted. However when I single quote it the variable isn't expanded.
read -ra hexCols <<< "$(grep ^$1 $mainConf | cut -d: -f2 | xargs)"I'm sure I'm missing something obvious but as I'm quite new to this I'm struggling to see what.
I hope someone can help!
https://redd.it/17m9bjb
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
line counting plugin
Hey people,
I've created a plugin that I want to share with you.
Here's the link: https://github.com/Nelliguns/line-counter-tmux
The reason for creating this plugin is that I received the question of how many lines of code it took to create a specific project of mine where I then started going through the different files and roughly summing them in my head. Which then sparked the idea of making this plugin.
Give it a try and let me now what you think, happy to receive feedback and ideas of improvements.
Hope you like it :)
https://redd.it/17mcp7b
@r_bash
Hey people,
I've created a plugin that I want to share with you.
Here's the link: https://github.com/Nelliguns/line-counter-tmux
The reason for creating this plugin is that I received the question of how many lines of code it took to create a specific project of mine where I then started going through the different files and roughly summing them in my head. Which then sparked the idea of making this plugin.
Give it a try and let me now what you think, happy to receive feedback and ideas of improvements.
Hope you like it :)
https://redd.it/17mcp7b
@r_bash
GitHub
GitHub - Nelliguns/line-counter-tmux
Contribute to Nelliguns/line-counter-tmux development by creating an account on GitHub.
Veriphone API for Laravel applications.
Veriphone API is a REST based JSON API. It provides a set of stateless endpoints that any program or web browser can call by sending a standard HTTP request. Veriphone will respond with a standard HTTP response carrying a JSON payload. This documentation describes these endpoints, their input/output parameters and authentication methods.
​
https://github.com/slvler/veriphone-service
https://redd.it/17mhvhb
@r_bash
Veriphone API is a REST based JSON API. It provides a set of stateless endpoints that any program or web browser can call by sending a standard HTTP request. Veriphone will respond with a standard HTTP response carrying a JSON payload. This documentation describes these endpoints, their input/output parameters and authentication methods.
​
https://github.com/slvler/veriphone-service
https://redd.it/17mhvhb
@r_bash
GitHub
GitHub - slvler/veriphone-service: veriphone.io service
veriphone.io service . Contribute to slvler/veriphone-service development by creating an account on GitHub.
Usernames from other files
Say I had a text file of usernames and in another bash noscript I needed to use those usernames for it to advance how would I make that so it basically Denys access if the username is not in the other file
https://redd.it/17mttty
@r_bash
Say I had a text file of usernames and in another bash noscript I needed to use those usernames for it to advance how would I make that so it basically Denys access if the username is not in the other file
https://redd.it/17mttty
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Batch rename files
I have a bunch of files that have long names.
The beginning part of the name is the same of everyfile, so what I want to do is batch rename all the files to remove the beginning section.
Is there a quick and easy way...
Say the files are called
Video Tutorial - Grade 11 - Lesson 1 - Introduction.mp4Video Tutorial - Grade 11 - Lesson 2 - Basics.mp4
I want the files to be named
Lesson 1 - Introduction.mp4
Lesson 2 - Basics.mp4
https://redd.it/17n96kr
@r_bash
I have a bunch of files that have long names.
The beginning part of the name is the same of everyfile, so what I want to do is batch rename all the files to remove the beginning section.
Is there a quick and easy way...
Say the files are called
Video Tutorial - Grade 11 - Lesson 1 - Introduction.mp4Video Tutorial - Grade 11 - Lesson 2 - Basics.mp4
I want the files to be named
Lesson 1 - Introduction.mp4
Lesson 2 - Basics.mp4
https://redd.it/17n96kr
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
usage of single key bind for multiple commands
Im trying to write a bash noscript which have multiple commands which have their own independent keybindings to run , but I want to cycle through these commands with tab. How can i do that?
https://redd.it/17ne28u
@r_bash
Im trying to write a bash noscript which have multiple commands which have their own independent keybindings to run , but I want to cycle through these commands with tab. How can i do that?
https://redd.it/17ne28u
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
sed html file?
I need to add a large number of sequential hyper links in a html file.
example (and 11 would be the incrementing variable):
look for ">11</td>"
replace with "><a href="11.mp3">11</a></td>
So my thought was to create an incrementing loop and use sed,
The problem I am having is likely escaping the html symbols.
Can someone show me a working noscript to accomplish this so I can see what I am doing wrong?
Thanks
​
The file with the first 10 links manually added.
https://pastebin.com/mQ8uYeF0
https://redd.it/17nern8
@r_bash
I need to add a large number of sequential hyper links in a html file.
example (and 11 would be the incrementing variable):
look for ">11</td>"
replace with "><a href="11.mp3">11</a></td>
So my thought was to create an incrementing loop and use sed,
The problem I am having is likely escaping the html symbols.
Can someone show me a working noscript to accomplish this so I can see what I am doing wrong?
Thanks
​
The file with the first 10 links manually added.
https://pastebin.com/mQ8uYeF0
https://redd.it/17nern8
@r_bash
Not familiar with bash syntax
What can I do? Is there a college level assignments on bash or anything like certs for bash noscripting only?
I know how to do something, but I need to keep googling the syntax and honestly, it's annoying, I am making lots of mistakes in syntax. It has been quite some time since I've studied about bash noscripting and still not being comfortable with it is concerning.
https://redd.it/17nki55
@r_bash
What can I do? Is there a college level assignments on bash or anything like certs for bash noscripting only?
I know how to do something, but I need to keep googling the syntax and honestly, it's annoying, I am making lots of mistakes in syntax. It has been quite some time since I've studied about bash noscripting and still not being comfortable with it is concerning.
https://redd.it/17nki55
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Become commands in Bash folders
https://programadorwebvalencia.com/become-commands-in-bash-folders/
https://redd.it/17nv5mo
@r_bash
https://programadorwebvalencia.com/become-commands-in-bash-folders/
https://redd.it/17nv5mo
@r_bash
Programador Web Valencia
Become commands in Bash folders
I want to show my focus to execute commands in Bash using watchers and folders. I named this trick Bash Folders. I had a problem. I needed to run a lot commands in files. For example, every day should transform videos (the extension isn’t relevant) to MP4.…
How to substitute in aliases
I'm doing this in my `.bashrc`
alias git-test="echo ${1}##*\/"
What I want to achieve is to get the last part of a url, for example from `https://www.reddit.com/r/bash/submit` get `submit`. But when I run it, it gives me nothing and I dont know why.
https://redd.it/17o8o38
@r_bash
I'm doing this in my `.bashrc`
alias git-test="echo ${1}##*\/"
What I want to achieve is to get the last part of a url, for example from `https://www.reddit.com/r/bash/submit` get `submit`. But when I run it, it gives me nothing and I dont know why.
https://redd.it/17o8o38
@r_bash