Help
I need help writing a bash noscript to delete every folder that is older than 6 months, and delete 3 folder a week and save 2 for month 4 to month 6. The folders have the following naming convention; “files20230425”, “files20230424” z
https://redd.it/12yw7yo
@r_bash
I need help writing a bash noscript to delete every folder that is older than 6 months, and delete 3 folder a week and save 2 for month 4 to month 6. The folders have the following naming convention; “files20230425”, “files20230424” z
https://redd.it/12yw7yo
@r_bash
Reddit
r/bash on Reddit: Help
Posted by u/Responsible_Bug_767 - No votes and 7 comments
5 Inbuilt Bash Variables That Every Developer Should Know
https://levelup.gitconnected.com/5-inbuilt-bash-variables-that-every-developer-should-know-a2d60721a472?sk=6debc2c4c3196f2fcd954690d7fb989f
https://redd.it/12z9snv
@r_bash
https://levelup.gitconnected.com/5-inbuilt-bash-variables-that-every-developer-should-know-a2d60721a472?sk=6debc2c4c3196f2fcd954690d7fb989f
https://redd.it/12z9snv
@r_bash
Medium
5 Inbuilt Bash Variables That Every Developer Should Know
Write modern, simple, informative shell noscripts with these shell variables.
filenames from a find / read loop being corrupted?
I have never seen this behavior before. This seems to be caused by running the python command line noscript "demucs". This utility from facebook will split individual instrument tracks from a song. When I saw how well it worked, of course I have to split my whole music library. In the course of doing so I found that when feeding it song file names from a `find` command, it would remove either 0, 1 or 2 characters from the front of the filename.
$ find . -type f -name '*.flac' | while read -r i; do \
echo "$i"
demucs -n htdemucs_ft -o ~/split --filename '{track} {stem}.{ext}' -j2 -d cpu --clip-mode rescale -- "$i"
done
Hiding the output from demucs, the result from the `echo "$i"` line is:
./02 California.flac
/08 Easily.flac
./01 Laughing And Not Being Normal.flac
/14 Butterfly.flac
./07 Artangels.flac
03 Scream (Ft. Aristophanes).flac
/06 Kill V. Maim.flac
./11 World Princess Ii.flac
05 Belly Of The Beat.flac
15 Realiti (Demo).flac
13 Life In The Vivid Dream.flac
/09 Pin.flac
./10 Realiti.flac
12 Venus Fly (Ft. Janelle Monae).flac
/04 Flesh Without Blood.flac
If the demucs command is removed, here is the output, which is what I expect:
./02 California.flac
./08 Easily.flac
./01 Laughing And Not Being Normal.flac
./14 Butterfly.flac
./07 Artangels.flac
./03 Scream (Ft. Aristophanes).flac
./06 Kill V. Maim.flac
./11 World Princess Ii.flac
./05 Belly Of The Beat.flac
./15 Realiti (Demo).flac
./13 Life In The Vivid Dream.flac
./09 Pin.flac
./10 Realiti.flac
./12 Venus Fly (Ft. Janelle Monae).flac
./04 Flesh Without Blood.flac
Any ideas how this can happen? I think that demucs is doing something weird, but it would think it shouldn't be able to modify this memory.
For completeness, I get the same behavior with this form:
while read -r file; do
demucs --etc
done < <(find blah)
https://redd.it/12zfuwq
@r_bash
I have never seen this behavior before. This seems to be caused by running the python command line noscript "demucs". This utility from facebook will split individual instrument tracks from a song. When I saw how well it worked, of course I have to split my whole music library. In the course of doing so I found that when feeding it song file names from a `find` command, it would remove either 0, 1 or 2 characters from the front of the filename.
$ find . -type f -name '*.flac' | while read -r i; do \
echo "$i"
demucs -n htdemucs_ft -o ~/split --filename '{track} {stem}.{ext}' -j2 -d cpu --clip-mode rescale -- "$i"
done
Hiding the output from demucs, the result from the `echo "$i"` line is:
./02 California.flac
/08 Easily.flac
./01 Laughing And Not Being Normal.flac
/14 Butterfly.flac
./07 Artangels.flac
03 Scream (Ft. Aristophanes).flac
/06 Kill V. Maim.flac
./11 World Princess Ii.flac
05 Belly Of The Beat.flac
15 Realiti (Demo).flac
13 Life In The Vivid Dream.flac
/09 Pin.flac
./10 Realiti.flac
12 Venus Fly (Ft. Janelle Monae).flac
/04 Flesh Without Blood.flac
If the demucs command is removed, here is the output, which is what I expect:
./02 California.flac
./08 Easily.flac
./01 Laughing And Not Being Normal.flac
./14 Butterfly.flac
./07 Artangels.flac
./03 Scream (Ft. Aristophanes).flac
./06 Kill V. Maim.flac
./11 World Princess Ii.flac
./05 Belly Of The Beat.flac
./15 Realiti (Demo).flac
./13 Life In The Vivid Dream.flac
./09 Pin.flac
./10 Realiti.flac
./12 Venus Fly (Ft. Janelle Monae).flac
./04 Flesh Without Blood.flac
Any ideas how this can happen? I think that demucs is doing something weird, but it would think it shouldn't be able to modify this memory.
For completeness, I get the same behavior with this form:
while read -r file; do
demucs --etc
done < <(find blah)
https://redd.it/12zfuwq
@r_bash
Reddit
r/bash on Reddit: filenames from a find / read loop being corrupted?
Posted by u/habys - No votes and 4 comments
Multiple case words
You can use
case $WORD in
pattern1)
function1
;;
pattern2|pattern3)
function2
;;
esac
to execute functions depending on the value of WORD. `pattern2|pattern3)` will execute if either `pattern2
Is there a way to have multiple WORDS, like
case $WORD1|$WORD2 in
pattern1)
true
;;
esac
, where the commands inside
https://redd.it/12zpjdw
@r_bash
You can use
case $WORD in
pattern1)
function1
;;
pattern2|pattern3)
function2
;;
esac
to execute functions depending on the value of WORD. `pattern2|pattern3)` will execute if either `pattern2
or pattern3` match `$WORD`.Is there a way to have multiple WORDS, like
case $WORD1|$WORD2 in
pattern1)
true
;;
esac
, where the commands inside
pattern_1) is executed if pattern_1 match either $WORD_1 or $WORD_2?https://redd.it/12zpjdw
@r_bash
Reddit
r/bash on Reddit: Multiple case words
Posted by u/Ladvarg - No votes and 2 comments
Linux/bash noscripting projects for resume
I have recently been learning linux and bash noscripting and i want to know what is the best way to apply this to hands on projects.
What are some projects i can work on to add to my resume? for beginners-intermediate
https://redd.it/12zzwv7
@r_bash
I have recently been learning linux and bash noscripting and i want to know what is the best way to apply this to hands on projects.
What are some projects i can work on to add to my resume? for beginners-intermediate
https://redd.it/12zzwv7
@r_bash
Reddit
r/bash on Reddit: Linux/bash noscripting projects for resume
Posted by u/Sebunza - No votes and 1 comment
echo -e doesn't work
I wrote a bash noscript with an ANSI Escape Sequence,
and it doesn't work, and I have no Idea why.
https://redd.it/130l286
@r_bash
I wrote a bash noscript with an ANSI Escape Sequence,
#!/bin/bash
echo -e "\33[2J"
and it doesn't work, and I have no Idea why.
https://redd.it/130l286
@r_bash
Reddit
r/bash on Reddit: echo -e doesn't work
Posted by u/Mental_Tim - No votes and 3 comments
save root user's crontab as owned by normal user
hi. tried this in sudo crontab -e:
@weekly crontab -l -u root | sudo tee /configs/crontab-root-$(date +"%F").bak
also this
@weekly sh -c "crontab -l -u root > /configs/crontab-root-$(date +"%F").bak"
but get this on ls -l
-rw------- 1 root root 1.5K Apr 27 20:20 crontab-root-2023-04-27.bak
-rw-r--r-- 1 ram ram 525 Apr 26 15:18 gunicorn-2023-04-26.service.bak
while I need to save crontab-root file as 775 or 750 (or what's best approach)
https://redd.it/130q9a9
@r_bash
hi. tried this in sudo crontab -e:
@weekly crontab -l -u root | sudo tee /configs/crontab-root-$(date +"%F").bak
also this
@weekly sh -c "crontab -l -u root > /configs/crontab-root-$(date +"%F").bak"
but get this on ls -l
-rw------- 1 root root 1.5K Apr 27 20:20 crontab-root-2023-04-27.bak
-rw-r--r-- 1 ram ram 525 Apr 26 15:18 gunicorn-2023-04-26.service.bak
while I need to save crontab-root file as 775 or 750 (or what's best approach)
https://redd.it/130q9a9
@r_bash
Reddit
r/bash on Reddit: save root user's crontab as owned by normal user
Posted by u/format_c_enter - No votes and no comments
RPM upgrade - Redhat package manager
RPM - Redhat package manager question. Need help on upgrading from RPM 4 to 5. I tried this command: /usr/lib/rpm/bin/dbupgrade.sh but it says there's no such file or directory. Any option to do a sudo install or other suggestions would be appreciated.
https://redd.it/131dxzq
@r_bash
RPM - Redhat package manager question. Need help on upgrading from RPM 4 to 5. I tried this command: /usr/lib/rpm/bin/dbupgrade.sh but it says there's no such file or directory. Any option to do a sudo install or other suggestions would be appreciated.
https://redd.it/131dxzq
@r_bash
Reddit
r/bash on Reddit: RPM upgrade - Redhat package manager
Posted by u/Feeling-Character-31 - No votes and 1 comment
Help create a noscript to open a folder from terminal in Mac
I want to open this folder from terminal by running a sh noscript.
open '/Users/xxx/Library/Group Containers/xxx.ru.keepcoder.Telegram/appstore/account-xxx/postbox/media'
So I created an .sh file, put the above line in it and try to run it, but it shows 'command not found'. What did I do wrong ?
https://redd.it/131l9i7
@r_bash
I want to open this folder from terminal by running a sh noscript.
open '/Users/xxx/Library/Group Containers/xxx.ru.keepcoder.Telegram/appstore/account-xxx/postbox/media'
So I created an .sh file, put the above line in it and try to run it, but it shows 'command not found'. What did I do wrong ?
https://redd.it/131l9i7
@r_bash
Reddit
r/bash on Reddit: Help create a noscript to open a folder from terminal in Mac
Posted by u/vineethjose - No votes and no comments
What does the ampersand mean in
Like, I understand what it does, it's basically read and translated as "redirect the standard error to standard output, and redirect the standard output of command to /dev/null, so that both stderr and stdout get discarded".
Okay, cool, I understand what
I could write this command line as
And it would still do what it's expected to do, so what's the point or meaning of the ampersand?
I understand that trailing ampersand at the very end of a command line makes a long-running command return immediately to the current shell while it runs the command in a background subshell, but this isn't a trailing ampersand as it's actually used before
https://redd.it/1328lk9
@r_bash
command > /dev/null 2>&1?command > /dev/null 2>&1Like, I understand what it does, it's basically read and translated as "redirect the standard error to standard output, and redirect the standard output of command to /dev/null, so that both stderr and stdout get discarded".
Okay, cool, I understand what
/dev/null is, what 2 and 1 represent, and what output redirection operators > do. But what does the & ampersand before 1 mean?I could write this command line as
command > /dev/null 2>1And it would still do what it's expected to do, so what's the point or meaning of the ampersand?
I understand that trailing ampersand at the very end of a command line makes a long-running command return immediately to the current shell while it runs the command in a background subshell, but this isn't a trailing ampersand as it's actually used before
&1, or at least I think so.https://redd.it/1328lk9
@r_bash
Reddit
r/bash on Reddit: What does the ampersand mean in `command > /dev/null 2>&1`?
Posted by u/ED9898A - No votes and 8 comments
How does cat
Can someone dissect in great details what's exactly going on when you run that
Or when you write a noscript and then output text via writing:
cat << EOF
------
Some text to display when this noscript is run
------
EOF
I have a vague idea of what's going on but I'd rather a shell guru explains it correctly, just so I don't assume things.
I know that EOF stands for End of File and that it's just a convention, I could use
What happens here is that
So
When
I get the general idea that
https://redd.it/132dgu9
@r_bash
cat << EOF exactly work?Can someone dissect in great details what's exactly going on when you run that
cat command with cat << EOF?cat << EOF > file.txtOr when you write a noscript and then output text via writing:
cat << EOF
------
Some text to display when this noscript is run
------
EOF
I have a vague idea of what's going on but I'd rather a shell guru explains it correctly, just so I don't assume things.
I know that EOF stands for End of File and that it's just a convention, I could use
abc instead and it'd still work.What happens here is that
cat << EOF lets you redirect inputs to cat until you type EOF to quit. cat will then output to the display what you just typed.So
cat << EOF > file.txt redirects everything you type to cat until the keyword you provided (EOF in our case) was entered, and when that happens, cat's output is redirected to be written to file.txt.When
EOF is entered, the shell? (or cat?) somehow knows the end of file is reached, and doesn't continue writing input to cat, how does that "magically" work? Is EOF detected by the shell interpreter or the cat command?I get the general idea that
cat << EOF tells the shell to give cat every line that follows, until the EOF is encountered again, I know what the lines do, I just don't understand the logic behind it. Does the redirection syntax signal to the shell that we only want cat to display whatever values of text that are only between the first EOF and the last EOF?https://redd.it/132dgu9
@r_bash
Reddit
r/bash on Reddit: How does cat `cat << EOF` exactly work?
Posted by u/ED9898A - No votes and 2 comments
How can I configure my bashrc so that the man command always check the number of columns available before re-rendering the text after I maximized the terminal window?
I have the following annoying pattern. I have the terminal emulator set to open at a certain geometry. When I open a man page, it's hard to read this way, so I maximize the window. The problem is the window background is max, but the text is still rendered as if it is limited to half the screen. Instead of using 211 cols, it still uses 86.
https://imgur.com/kMGIUSB
I tried some ChatGPT, but I failed. I guess I don't know how to ask. It told me to export
So as of now I do it manually (q to exit less, arrow key up and voilà the text is rendered out with 211 columns). I tried to change the man pager to most. Same story. I tried different terminal. The same. I see nvim or nano don't have this problem. The column size gets recalculated when the window is maximized, neither less by itself. For example,
Also, worth saying with
Any help?
https://redd.it/132nrry
@r_bash
I have the following annoying pattern. I have the terminal emulator set to open at a certain geometry. When I open a man page, it's hard to read this way, so I maximize the window. The problem is the window background is max, but the text is still rendered as if it is limited to half the screen. Instead of using 211 cols, it still uses 86.
https://imgur.com/kMGIUSB
I tried some ChatGPT, but I failed. I guess I don't know how to ask. It told me to export
MANPAGER='less -r' and source it. That didn't work. I asked a bit more and told me to try trap 'COLUMNS=$(tput cols)' SIGWINCH Still does not work for me.So as of now I do it manually (q to exit less, arrow key up and voilà the text is rendered out with 211 columns). I tried to change the man pager to most. Same story. I tried different terminal. The same. I see nvim or nano don't have this problem. The column size gets recalculated when the window is maximized, neither less by itself. For example,
less /var/log/syslog the text gets rendered taking into account the column size when I toggle between maximized and unmaximized.Also, worth saying with
man the problem doesn't happen if the terminal is maximized when initially opening the page, I can toggle the terminal window size and the text gets re-rendered just fine. It only has an issue when I try to increase the size of the window and for whatever reason the variable that holds the size of the available columns doesn't get pass.Any help?
https://redd.it/132nrry
@r_bash
Imgur
Discover the magic of the internet at Imgur, a community powered entertainment destination. Lift your spirits with funny jokes, trending memes, entertaining gifs, inspiring stories, viral videos, and so much more from users.
Hello I made this to learn a little bit about bash, got any feedback?
https://github.com/cch000/power\_management
https://redd.it/132ps5s
@r_bash
https://github.com/cch000/power\_management
https://redd.it/132ps5s
@r_bash
GitHub
GitHub - cch000/power_management: Change cpu governors and scaling drivers when plugging /unplugging
Change cpu governors and scaling drivers when plugging /unplugging - GitHub - cch000/power_management: Change cpu governors and scaling drivers when plugging /unplugging
Mainline Nginx for Amazon Linux 2023
I am unable to install nginx from nginx repo instead it is installing nginx from amazonlinux repo again and again after following this [instructions\](http://nginx.org/en/linux\_packages.html#Amazon-Linux:\~:text=To%20set%20up%20the%20yum%20repository%20for%20Amazon%20Linux%202023%2C%20create%20the%20file%20named%20/etc/yum.repos.d/nginx.repo%20with) :
So, after failing i did
`dnf config-manager --add-repo http://nginx.org/packages/mainline/amzn/2023/`
'yum install nginx -y`
and came up with this error
```
nginx mainline repo 21 kB/s | 8.1 kB 00:00
created by dnf config-manager from http://nginx.org/packages/mainline/amzn/2023/7.1 kB/s | 3.3 kB 00:00
Errors during downloading metadata for repository 'nginx.org_packages_mainline_amzn_2023_':
\- Status code: 404 for http://nginx.org/packages/mainline/amzn/2023/repodata/repomd.xml (IP: 3.125.197.172)
Error: Failed to download metadata for repo 'nginx.org_packages_mainline_amzn_2023_': Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried
Ignoring repositories: nginx.org_packages_mainline_amzn_2023_
Dependencies resolved.
```
​
https://preview.redd.it/7luxns5uatwa1.png?width=1899&format=png&auto=webp&v=enabled&s=ae9968d26e7691602c24fa3e482a4aa6ad9b175c
there should be nginx-mainline in the first row of repository.
How do i resolve this i can't understand .
https://redd.it/132qu2r
@r_bash
I am unable to install nginx from nginx repo instead it is installing nginx from amazonlinux repo again and again after following this [instructions\](http://nginx.org/en/linux\_packages.html#Amazon-Linux:\~:text=To%20set%20up%20the%20yum%20repository%20for%20Amazon%20Linux%202023%2C%20create%20the%20file%20named%20/etc/yum.repos.d/nginx.repo%20with) :
So, after failing i did
`dnf config-manager --add-repo http://nginx.org/packages/mainline/amzn/2023/`
'yum install nginx -y`
and came up with this error
```
nginx mainline repo 21 kB/s | 8.1 kB 00:00
created by dnf config-manager from http://nginx.org/packages/mainline/amzn/2023/7.1 kB/s | 3.3 kB 00:00
Errors during downloading metadata for repository 'nginx.org_packages_mainline_amzn_2023_':
\- Status code: 404 for http://nginx.org/packages/mainline/amzn/2023/repodata/repomd.xml (IP: 3.125.197.172)
Error: Failed to download metadata for repo 'nginx.org_packages_mainline_amzn_2023_': Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried
Ignoring repositories: nginx.org_packages_mainline_amzn_2023_
Dependencies resolved.
```
​
https://preview.redd.it/7luxns5uatwa1.png?width=1899&format=png&auto=webp&v=enabled&s=ae9968d26e7691602c24fa3e482a4aa6ad9b175c
there should be nginx-mainline in the first row of repository.
How do i resolve this i can't understand .
https://redd.it/132qu2r
@r_bash
Best courses to learn bash noscripting
I want to learn bash noscripting. I know there are lot of resources out there but i want a course or site where they give small tasks or assignments along with the video.
I want to learn end to end. Like using awk,sed etc
https://redd.it/132sd5a
@r_bash
I want to learn bash noscripting. I know there are lot of resources out there but i want a course or site where they give small tasks or assignments along with the video.
I want to learn end to end. Like using awk,sed etc
https://redd.it/132sd5a
@r_bash
Reddit
r/bash on Reddit: Best courses to learn bash noscripting
Posted by u/Neither_Wallaby_9033 - No votes and no comments
Why aren't my aliased commands registering when ran with sudo?
And yes, I have "alias sudo='sudo '" in both my "~/.bashrc" and "/etc/bashrc" files along with the rest of my aliases.
I use fish (with the same aliases in "~/.config/fish/config.fish") too, but there's the same problem whether I'm using the commands with sudo in both fish and bash.
https://redd.it/132phhm
@r_bash
And yes, I have "alias sudo='sudo '" in both my "~/.bashrc" and "/etc/bashrc" files along with the rest of my aliases.
I use fish (with the same aliases in "~/.config/fish/config.fish") too, but there's the same problem whether I'm using the commands with sudo in both fish and bash.
https://redd.it/132phhm
@r_bash
Reddit
r/bash on Reddit: Why aren't my aliased commands registering when ran with sudo?
Posted by u/I-Machina - 1 vote and 4 comments
Why does
Assume
Why does redirecting stdrr to stdout file denoscriptor via using the single overwrite operator works as expected:
While using the double redirection operator for appending doesn't?
I'm on bash 3.2 that comes shipped with macOS if anyone's wondering.
https://redd.it/132yqr3
@r_bash
> /dev/null 2>&1 work while > /dev/null 2>>&1 doesn't?Assume
abcd is a file that doesn't exist.Why does redirecting stdrr to stdout file denoscriptor via using the single overwrite operator works as expected:
cat abcd > /dev/null 2>&1While using the double redirection operator for appending doesn't?
cat abcd > /dev/null 2>>&1I'm on bash 3.2 that comes shipped with macOS if anyone's wondering.
https://redd.it/132yqr3
@r_bash
Reddit
r/bash on Reddit: Why does `> /dev/null 2>&1` work while `> /dev/null 2>>&1` doesn't?
Posted by u/ED9898A - No votes and 1 comment
Improvement in my "=" alias which bookmarks directories and creates shortcuts
I've made an improvement in my favorite bash alias (actually a function) that I use it to navigate all over the filesystem, bookmark where I am, go back, and move files around.
The alias "=" remembers, or bookmarks your current directory.
Usage examples:
% = A # bookmark current directory as "A"
% A # go to directory bookmarked as A
% cp file $A # copy file to bookmarked directory
% cp file "$A" # as above, but if the directory contains spaces, etc.
% cp $A/file $B # copy file between 2 bookmarked directories when you are in
# a third directory, etc.
Add this to your \~/.bash_aliases file and then type ". \~/.bash_aliases"
function = () { # remember current directory using "= varname"
# and create alias/function that changes directory
# by grymoire - 4/30/2023
eval "$1"='$(pwd)'
eval function "$1" "() { cd \"\$$1\" ; }"
}
Example of usage:
me@cpu:~/$ cd ~/Downloads/ # go to my downloads directory
me@cpu:~/Downloads$ = D # bookmark it as "D" for Downloads
me@cpu:~/Downloads$ cd /media/me/FLIPPER\ SD/ # switch toi my flipper directory
me@cpu:/media/me/FLIPPER SD$ = F # bookmark it as "F" for flipper
me@cpu:/media/me/FLIPPER SD$ D # go back to my Downloads directory
me@cpu:~/Downloads$ cp file.tar $F # copy file to my flipper directory
cp: target 'SD' is not a directory # oops. Forgot - a space in name
me@cpu:~/Downloads$ cp file.tar "$F" # do it the right way
me@cpu:~/Downloads$ F # jump back to my flipper directory
me@cpu:/media/me/FLIPPER SD$ rm file.tar # move/delete the file
rm: remove regular empty file 'file.tar'? y
me@cpu:/media/me/FLIPPER SD$ D # go back to my downloads directory
me@cpu:~/Downloads$
I find this much easier to use than the pushd/popd commands. This is also the first time I had a function, that when called, defines a new function. Cool!
I often download files and copy them into my \~/Git directory, and this makes it easy to navigate and copy files all over the filesystem. Hope you like it.
https://redd.it/133tyzt
@r_bash
I've made an improvement in my favorite bash alias (actually a function) that I use it to navigate all over the filesystem, bookmark where I am, go back, and move files around.
The alias "=" remembers, or bookmarks your current directory.
Usage examples:
% = A # bookmark current directory as "A"
% A # go to directory bookmarked as A
% cp file $A # copy file to bookmarked directory
% cp file "$A" # as above, but if the directory contains spaces, etc.
% cp $A/file $B # copy file between 2 bookmarked directories when you are in
# a third directory, etc.
Add this to your \~/.bash_aliases file and then type ". \~/.bash_aliases"
function = () { # remember current directory using "= varname"
# and create alias/function that changes directory
# by grymoire - 4/30/2023
eval "$1"='$(pwd)'
eval function "$1" "() { cd \"\$$1\" ; }"
}
Example of usage:
me@cpu:~/$ cd ~/Downloads/ # go to my downloads directory
me@cpu:~/Downloads$ = D # bookmark it as "D" for Downloads
me@cpu:~/Downloads$ cd /media/me/FLIPPER\ SD/ # switch toi my flipper directory
me@cpu:/media/me/FLIPPER SD$ = F # bookmark it as "F" for flipper
me@cpu:/media/me/FLIPPER SD$ D # go back to my Downloads directory
me@cpu:~/Downloads$ cp file.tar $F # copy file to my flipper directory
cp: target 'SD' is not a directory # oops. Forgot - a space in name
me@cpu:~/Downloads$ cp file.tar "$F" # do it the right way
me@cpu:~/Downloads$ F # jump back to my flipper directory
me@cpu:/media/me/FLIPPER SD$ rm file.tar # move/delete the file
rm: remove regular empty file 'file.tar'? y
me@cpu:/media/me/FLIPPER SD$ D # go back to my downloads directory
me@cpu:~/Downloads$
I find this much easier to use than the pushd/popd commands. This is also the first time I had a function, that when called, defines a new function. Cool!
I often download files and copy them into my \~/Git directory, and this makes it easy to navigate and copy files all over the filesystem. Hope you like it.
https://redd.it/133tyzt
@r_bash
Reddit
r/bash on Reddit: Improvement in my "=" alias which bookmarks directories and creates shortcuts
Posted by u/grymoire - No votes and 1 comment
"Immortal" Bash noscripts, using inline Nix and a special header block
I've been learning Nix and as an application for a job (yes, still looking for work) I wrote a single-file Bash app that provided a TUI to look up food truck eateries (downloaded and cached from an online source CSV) based on a filter and sort by distance from you. To make this work I needed to rely on a few external binaries- the right versions of
I succeeded in this task =) thanks to /u/Aidenn0 and this thread (which actually had other solutions to this problem, but I liked this one because I could include it all in the same file).
So now, not only does it fall back to some basic dependency checking if you don't have Nix installed (or you source the file instead of running it directly), not only does it know how to find and install any needed dependencies if you DO have nix installed, not only does it run all this in a "pure" environment that is constructed on-the-fly, not only does it actually re-run itself with the right Bash version (which is why it starts with
Accomplishing all this in 1 file was a bit complex (code golfing? Yeah, kinda, maybe), so I tried to comment heavily. (For any other explanations, you could ask ChatGPT, which was actually very helpful to me as well!)
Here is the gist. The "magic Nix" section is the "DEPENDENCY MANAGEMENT" section. You'd have to adapt this to your use-case (such as whitelisting the correct env vars and specifying the right dependencies), but maybe there are some ideas in here you can use in your own noscripting projects. I'm sure many of you have encountered the situation where a noscript you relied on stopped working all of a sudden because of a change to something it depended on...
Negatives? Well, the first time you run the noscript, there's a multi second delay as it gets and caches all the deps into the "Nix store" (very cool to watch though!), and any further time you run it there's a small (sub-second) delay as it verifies all the specified deps are still available in cache (cache TTL depends on your Nix config). That's only if you have Nix installed. (Maybe I could add an env option to
Thoughts? Suggestions?
https://redd.it/133w2sh
@r_bash
I've been learning Nix and as an application for a job (yes, still looking for work) I wrote a single-file Bash app that provided a TUI to look up food truck eateries (downloaded and cached from an online source CSV) based on a filter and sort by distance from you. To make this work I needed to rely on a few external binaries- the right versions of
bash, GNU awk, jq, curl, csvquote and this neat thing called `gum`. I finished it but in the course of testing it I realized that I got it running fine on Linux (NixOS) but it acted a bit wonky on macOS (and since I was actually applying for a primarily Elixir-lang job, I knew most devs would be on Macs). And the reason it was wonky was due to a version difference in both Bash and Awk. At that point I decided to go for my "stretch goal" of getting everything and all necessary dependencies optionally bootstrapped via Nix so that, assuming one had Nix installed and an Internet connection, the noscript would be "guaranteed" to run for the foreseeable future and would automatically (!!!) download (or read from cache), install, and make available the right dependencies AND re-run the noscript with the right version of Bash.I succeeded in this task =) thanks to /u/Aidenn0 and this thread (which actually had other solutions to this problem, but I liked this one because I could include it all in the same file).
So now, not only does it fall back to some basic dependency checking if you don't have Nix installed (or you source the file instead of running it directly), not only does it know how to find and install any needed dependencies if you DO have nix installed, not only does it run all this in a "pure" environment that is constructed on-the-fly, not only does it actually re-run itself with the right Bash version (which is why it starts with
sh, actually, in case you don't even have Bash installed!), it also has a (pretty basic) test suite, AND test data, all in the same file.Accomplishing all this in 1 file was a bit complex (code golfing? Yeah, kinda, maybe), so I tried to comment heavily. (For any other explanations, you could ask ChatGPT, which was actually very helpful to me as well!)
Here is the gist. The "magic Nix" section is the "DEPENDENCY MANAGEMENT" section. You'd have to adapt this to your use-case (such as whitelisting the correct env vars and specifying the right dependencies), but maybe there are some ideas in here you can use in your own noscripting projects. I'm sure many of you have encountered the situation where a noscript you relied on stopped working all of a sudden because of a change to something it depended on...
Negatives? Well, the first time you run the noscript, there's a multi second delay as it gets and caches all the deps into the "Nix store" (very cool to watch though!), and any further time you run it there's a small (sub-second) delay as it verifies all the specified deps are still available in cache (cache TTL depends on your Nix config). That's only if you have Nix installed. (Maybe I could add an env option to
SKIP_NIX if you are sure your existing session already has all the right deps available.)Thoughts? Suggestions?
https://redd.it/133w2sh
@r_bash
GitHub
GitHub - charmbracelet/gum: A tool for glamorous shell noscripts 🎀
A tool for glamorous shell noscripts 🎀. Contribute to charmbracelet/gum development by creating an account on GitHub.
Question for the Greybeards - How to redirect permission Denied to an Error File
Have file a
want to do something like
My goal is to get the resulting permission denied into the error.log, but this does not work and the error is printed to the terminal.
Note that I'm purposely running as a regular user as I'm focused on the output redirection atm.
Not a school assignment, but saw sometthing like this in another reddit, and it got me wondering how to accomplish this.
Any Ideas? Suggestions or help is greatly appreciated.
https://redd.it/1343i2i
@r_bash
Have file a
SomeFile.txt where owner is root.want to do something like
echo "Text" >> SomeFile.txt 2> error.logMy goal is to get the resulting permission denied into the error.log, but this does not work and the error is printed to the terminal.
Note that I'm purposely running as a regular user as I'm focused on the output redirection atm.
Not a school assignment, but saw sometthing like this in another reddit, and it got me wondering how to accomplish this.
Any Ideas? Suggestions or help is greatly appreciated.
https://redd.it/1343i2i
@r_bash
Reddit
r/bash on Reddit: Question for the Greybeards - How to redirect permission Denied to an Error File
Posted by u/RandomXUsr - No votes and 1 comment
My noscript works but why?
Hello there;
So I have this txt file that contains 300 something links to free (as in free of charge not pirated) JS tutorials from a course in my language.
The site that offers the course suggested that students should drop the links one by one into IDM, but I thought to hell with that! We are smarter than that aren't we? :)
So I wrote a quick noscript like this:
and it worked. all the links in that txt file were downloaded with no problem.
But I have a question now. why did it work when I didn't use the correct array syntax?
shouldn't I have done something like this?
is it something about wget that made it work or am I missing something about bash?
https://redd.it/1346wl8
@r_bash
Hello there;
So I have this txt file that contains 300 something links to free (as in free of charge not pirated) JS tutorials from a course in my language.
The site that offers the course suggested that students should drop the links one by one into IDM, but I thought to hell with that! We are smarter than that aren't we? :)
So I wrote a quick noscript like this:
dl_list=$(cat ~/downloadlist.txt)
for i in $dl_list; do
wget $i
done
and it worked. all the links in that txt file were downloaded with no problem.
But I have a question now. why did it work when I didn't use the correct array syntax?
shouldn't I have done something like this?
dl_list=$(cat ~/downloadlist.txt)
IFS=$'\n' read -d '' -r -a LINKS < "$dl_list"
for link in "${LINKS[@]}"
do
wget "$link"
done
is it something about wget that made it work or am I missing something about bash?
https://redd.it/1346wl8
@r_bash