How to write a mounted shared path
I haven't touched bash or cbash in years and today i installed a ubuntu VM client on a windows OS.
The VM shares a folder, and i'm planning to convert a few noscripts into bash (or whatever) which i previously ran in windows batch files.
The question i have is how do i write the path?
The path in windows might be e:/shared
I think the folder in ubuntu is /mnt/hgfs/shared
Is /mnt/hgfs/shared the path i use in a bash noscript file?
Eg., Delete pdfs in a subfolder might be something like "rm /mnt/hgfs/shared/no-more-pdfs/*.pdf"?
Thx
A
https://redd.it/13ngzg4
@r_bash
I haven't touched bash or cbash in years and today i installed a ubuntu VM client on a windows OS.
The VM shares a folder, and i'm planning to convert a few noscripts into bash (or whatever) which i previously ran in windows batch files.
The question i have is how do i write the path?
The path in windows might be e:/shared
I think the folder in ubuntu is /mnt/hgfs/shared
Is /mnt/hgfs/shared the path i use in a bash noscript file?
Eg., Delete pdfs in a subfolder might be something like "rm /mnt/hgfs/shared/no-more-pdfs/*.pdf"?
Thx
A
https://redd.it/13ngzg4
@r_bash
Reddit
r/bash on Reddit: How to write a mounted shared path
Posted by u/PandaEquivalent - No votes and no comments
Can't get archiving backup noscript to work
Following a readout of a noscript in the 'Linux Command Line and Shell Script BIBLE (4th Ed.)', and it doesn't seem to archive the directories specified in the files-to-backup.txt file; rather, I get a 45B 'archive<today's-date>.tar.gz' file (in the correct periodic directory, at least) that's completely empty.
It does use an interesting method of building the $file_list variable, though:
#!/bin/bash
#DailyArchive - Archive designated files & directories
######## Variables ########################################
#
# Gather the Current Date
#
today=$(date +%y%m%d)
#
# Set Archive filename
#
backupfile=archive$today.tar.gz
#
# Set configuration and destination files
#
basedir=/mnt/j
configfile=$basedir/archive/files-to-backup.txt
period=daily
basedest=$basedir/archive/$period
destination=$basedest/$backupfile
#
# Set desired number number of maintained backups
#
backups=5
######### Functions #######################################
prunebackups() {
local directory="$1" # Directory path
local numarchives="$2" # Number of archives to maintain
# Check if the directory exists
if [ ! -d "$directory" ]
then
echo "Directory does not exist: $directory"
return 1
fi
# Check if there are enough archives in the directory to warrant pruning
local numfiles=$(find "$directory" -maxdepth 1 -type f | wc -l)
if (( numfiles >= numarchives )) # If there are...
then
# ...delete the oldest archive
local numfilestodelete=$(( numfiles - numarchives + 1 ))
local filestodelete=$(find "$directory" -maxdepth 1 -type f -printf '%T@ %p\n' | sort -n\
| head -n "$numfilestodelete" | awk '{print $2}')
echo
echo "Deleting the following backup:"
echo "$filestodelete"
sudo rm -f "$filestodelete"
echo "Continuing with backup..."
fi
}
######### Main Script #####################################
#
# Check Backup Config file exists
#
if [ -f "$configfile" ] # Make sure the config file still exists.
then # If it exists, do nothing and carry on.
echo
else # If it doesn't exist, issue an error & exit the noscript.
echo
echo "$(basename "$0"): Error: $configfile does not exist."
echo "Backup not completed due to missing configuration file."
echo
exit 1
fi
#
# Check to make sure the desired number of maintained backups isn't exceeded.
#
prunebackups $basedest $backups || { echo "$(basename "$0"): Error: Unable to prune backup\
directory. Exiting." >&2 ; exit 1; }
#
# Build the names of all the files to backup.
#
fileno=1 # Start on line 1 of the Config File.
exec 0< "$configfile" # Redirect Std Input to the name of the Config File.
read filename # Read first record.
while [ "$?" -eq 0 ] # Create list of files to backup.
do
# Make sure the file or directory exists.
if [ -f "$filename" ] || -d "$file_name"
then
# If the file exists, add its name to the list.
filelist="$filelist $filename"
else
# If the file does not exist, issue a warning.
echo
echo "$(basename "$0"): Warning: $filename does not exist."
echo "Obviously, I will not include it in this archive."
echo "It is listed on line $fileno of the config file."
echo "Continuing to build archive list..."
echo
fi
fileno=$((fileno + 1)) # Increment the Line/File number by one.
read filename # Read the next record.
done
########################################
#
# Back up
Following a readout of a noscript in the 'Linux Command Line and Shell Script BIBLE (4th Ed.)', and it doesn't seem to archive the directories specified in the files-to-backup.txt file; rather, I get a 45B 'archive<today's-date>.tar.gz' file (in the correct periodic directory, at least) that's completely empty.
It does use an interesting method of building the $file_list variable, though:
#!/bin/bash
#DailyArchive - Archive designated files & directories
######## Variables ########################################
#
# Gather the Current Date
#
today=$(date +%y%m%d)
#
# Set Archive filename
#
backupfile=archive$today.tar.gz
#
# Set configuration and destination files
#
basedir=/mnt/j
configfile=$basedir/archive/files-to-backup.txt
period=daily
basedest=$basedir/archive/$period
destination=$basedest/$backupfile
#
# Set desired number number of maintained backups
#
backups=5
######### Functions #######################################
prunebackups() {
local directory="$1" # Directory path
local numarchives="$2" # Number of archives to maintain
# Check if the directory exists
if [ ! -d "$directory" ]
then
echo "Directory does not exist: $directory"
return 1
fi
# Check if there are enough archives in the directory to warrant pruning
local numfiles=$(find "$directory" -maxdepth 1 -type f | wc -l)
if (( numfiles >= numarchives )) # If there are...
then
# ...delete the oldest archive
local numfilestodelete=$(( numfiles - numarchives + 1 ))
local filestodelete=$(find "$directory" -maxdepth 1 -type f -printf '%T@ %p\n' | sort -n\
| head -n "$numfilestodelete" | awk '{print $2}')
echo
echo "Deleting the following backup:"
echo "$filestodelete"
sudo rm -f "$filestodelete"
echo "Continuing with backup..."
fi
}
######### Main Script #####################################
#
# Check Backup Config file exists
#
if [ -f "$configfile" ] # Make sure the config file still exists.
then # If it exists, do nothing and carry on.
echo
else # If it doesn't exist, issue an error & exit the noscript.
echo
echo "$(basename "$0"): Error: $configfile does not exist."
echo "Backup not completed due to missing configuration file."
echo
exit 1
fi
#
# Check to make sure the desired number of maintained backups isn't exceeded.
#
prunebackups $basedest $backups || { echo "$(basename "$0"): Error: Unable to prune backup\
directory. Exiting." >&2 ; exit 1; }
#
# Build the names of all the files to backup.
#
fileno=1 # Start on line 1 of the Config File.
exec 0< "$configfile" # Redirect Std Input to the name of the Config File.
read filename # Read first record.
while [ "$?" -eq 0 ] # Create list of files to backup.
do
# Make sure the file or directory exists.
if [ -f "$filename" ] || -d "$file_name"
then
# If the file exists, add its name to the list.
filelist="$filelist $filename"
else
# If the file does not exist, issue a warning.
echo
echo "$(basename "$0"): Warning: $filename does not exist."
echo "Obviously, I will not include it in this archive."
echo "It is listed on line $fileno of the config file."
echo "Continuing to build archive list..."
echo
fi
fileno=$((fileno + 1)) # Increment the Line/File number by one.
read filename # Read the next record.
done
########################################
#
# Back up
the files and Compress Archive
#
echo "Starting archive..."
echo
sudo tar -czf "$destination" "$filelist" 2> /dev/null
echo "Archive completed"
echo "Resulting archive file is: $destination."
echo
exit
Now, I have modified the noscript, adding the 'prune\backups()' function, but something doesn't quite seem right though, and I can't put my finger on what it is. Can anyone see either where I've screwed up, or if it's just something with the noscript itself?
https://redd.it/13np7cp
@r_bash
#
echo "Starting archive..."
echo
sudo tar -czf "$destination" "$filelist" 2> /dev/null
echo "Archive completed"
echo "Resulting archive file is: $destination."
echo
exit
Now, I have modified the noscript, adding the 'prune\backups()' function, but something doesn't quite seem right though, and I can't put my finger on what it is. Can anyone see either where I've screwed up, or if it's just something with the noscript itself?
https://redd.it/13np7cp
@r_bash
Reddit
r/bash on Reddit: Can't get archiving backup noscript to work
Posted by u/StrangeCrunchy1 - No votes and no comments
Is there a way to record bash keyboard shortcuts in a command line noscript?
When I use specific shortcuts on a line such of Control+U, does that save to the noscript file? It doesn't create any output and nothing shows up when I open the file with cat.
On the other hand, when I open the file using Notepad, it shows the line I deleted with Control+U followed by " [K" is that the indicator that a shortcut was used on the line?
https://redd.it/13nqlcm
@r_bash
When I use specific shortcuts on a line such of Control+U, does that save to the noscript file? It doesn't create any output and nothing shows up when I open the file with cat.
On the other hand, when I open the file using Notepad, it shows the line I deleted with Control+U followed by " [K" is that the indicator that a shortcut was used on the line?
https://redd.it/13nqlcm
@r_bash
Reddit
r/bash on Reddit: Is there a way to record bash keyboard shortcuts in a command line noscript?
Posted by u/executivecarrot - No votes and 1 comment
Only download if file doesn't exist
Wrote this Bash noscript to download a file and place it in a folder however it's re-downloading every time it's run. I'd like for the download to only occur if the file does not already exist.
#!/bin/bash
# Download files from Github repo to /tmp/appfolder
URLDOWNLOAD1="https://raw.githubusercontent.com/Work/Repo/main/appfolder/logo.png";
TEMPDIR="appfolder";
FILENAME="$(basename $URLDOWNLOAD1)";
DOWNLOADFILE="/tmp/$TEMPDIR/$FILENAME";
if ! -d "/tmp/$TEMPDIR" ; then
mkdir -p "/tmp/$TEMPDIR";
fi;
curl -L --silent -o "$DOWNLOADFILE" "$URLDOWNLOAD1";
if -e $DOWNLOADFILE ; then
echo "$DOWNLOADFILE - Success";
else
echo "logo.png Download failed";
fi
Any assistance would be greatly appreciated!
https://redd.it/13of1p1
@r_bash
Wrote this Bash noscript to download a file and place it in a folder however it's re-downloading every time it's run. I'd like for the download to only occur if the file does not already exist.
#!/bin/bash
# Download files from Github repo to /tmp/appfolder
URLDOWNLOAD1="https://raw.githubusercontent.com/Work/Repo/main/appfolder/logo.png";
TEMPDIR="appfolder";
FILENAME="$(basename $URLDOWNLOAD1)";
DOWNLOADFILE="/tmp/$TEMPDIR/$FILENAME";
if ! -d "/tmp/$TEMPDIR" ; then
mkdir -p "/tmp/$TEMPDIR";
fi;
curl -L --silent -o "$DOWNLOADFILE" "$URLDOWNLOAD1";
if -e $DOWNLOADFILE ; then
echo "$DOWNLOADFILE - Success";
else
echo "logo.png Download failed";
fi
Any assistance would be greatly appreciated!
https://redd.it/13of1p1
@r_bash
findpick - General purpose file picker combining "find" command with a fuzzy finder
https://github.com/thingsiplay/findpick
https://redd.it/13oj98j
@r_bash
https://github.com/thingsiplay/findpick
https://redd.it/13oj98j
@r_bash
GitHub
GitHub - thingsiplay/findpick: General purpose file picker combining "find" command with a fuzzy finder.
General purpose file picker combining "find" command with a fuzzy finder. - GitHub - thingsiplay/findpick: General purpose file picker combining "find" command with a fuzzy finder.
Pipelight - Automation with Typenoscript{Bash} 🤌
I needed something to glue commands together but I prefer using javanoscript syntax over bash conditionals, loops and functions (yes i am evil 😈)
It has matured over the years, has been roasted, improved, refactored, and I think it has become stable enough to share it once again!
It's merely bash wrapped with typenoscript , with extra automation super powers 🦸
Documentation still improving: https://pipelight.dev/
I leave this here for the ones who need this kind of tool and hope you will find it usefull 😄
https://redd.it/13olxdi
@r_bash
I needed something to glue commands together but I prefer using javanoscript syntax over bash conditionals, loops and functions (yes i am evil 😈)
It has matured over the years, has been roasted, improved, refactored, and I think it has become stable enough to share it once again!
It's merely bash wrapped with typenoscript , with extra automation super powers 🦸
Documentation still improving: https://pipelight.dev/
I leave this here for the ones who need this kind of tool and hope you will find it usefull 😄
https://redd.it/13olxdi
@r_bash
Pipelight
Automation pipelines but easier.
Protecting SSHD's Listening Port with Port Knocking (or better)
Hi all
Whenever I set up a Linux box/VPS,
the first thing I do is change SSHD's Listening Port to something different than the default port.
I would like to add another protection to it, and start using Port Knocking,
so the port would appear Closed/NotListening to anyone,
except me, when I want to connect.
Can you please tell me what you recommend to use?
And also:
Is there something more advanced than Port Knocking that I should check,
for protecting the listening port?
Thank you very much
https://redd.it/13onqb7
@r_bash
Hi all
Whenever I set up a Linux box/VPS,
the first thing I do is change SSHD's Listening Port to something different than the default port.
I would like to add another protection to it, and start using Port Knocking,
so the port would appear Closed/NotListening to anyone,
except me, when I want to connect.
Can you please tell me what you recommend to use?
And also:
Is there something more advanced than Port Knocking that I should check,
for protecting the listening port?
Thank you very much
https://redd.it/13onqb7
@r_bash
Reddit
r/bash on Reddit: Protecting SSHD's Listening Port with Port Knocking (or better)
Posted by u/spaceman1000 - No votes and no comments
print $0 giving me unexpected result
Good afternoon, I am relatively new to using awk commands but I am running into a small issue with a output that involves $0.
I am reading in trade_data.csv.small:
sym,price,size,side,market,time,id
MDT,72.34000000,100,Short,NASDAQ,10:00:00.146882,1180355
MDT,72.35000000,125,Short,NASDAQ,10:00:00.165655,1180537
​
This is my awk line:
awk -F "[,\]" 'NR>1 {if ($3 == 100) print $0, " | 100 "; else print $0, " | not 100 | "}' trade_data.csv.small
​
The output is:
| 100 4000000,100,Short,NASDAQ,10:00:00.146882,1180355
| not 100 | 0,125,Short,NASDAQ,10:00:00.165655,1180537
​
I thought that the output would be something like:
MDT,72.34000000,100,Short,NASDAQ,10:00:00.146882,1180355 | 100
MDT,72.35000000,125,Short,NASDAQ,10:00:00.165655,1180537 | not 100
​
What am I doing wrong here?
Thank you in advance for your insight(s).
https://redd.it/13oxjfs
@r_bash
Good afternoon, I am relatively new to using awk commands but I am running into a small issue with a output that involves $0.
I am reading in trade_data.csv.small:
sym,price,size,side,market,time,id
MDT,72.34000000,100,Short,NASDAQ,10:00:00.146882,1180355
MDT,72.35000000,125,Short,NASDAQ,10:00:00.165655,1180537
​
This is my awk line:
awk -F "[,\]" 'NR>1 {if ($3 == 100) print $0, " | 100 "; else print $0, " | not 100 | "}' trade_data.csv.small
​
The output is:
| 100 4000000,100,Short,NASDAQ,10:00:00.146882,1180355
| not 100 | 0,125,Short,NASDAQ,10:00:00.165655,1180537
​
I thought that the output would be something like:
MDT,72.34000000,100,Short,NASDAQ,10:00:00.146882,1180355 | 100
MDT,72.35000000,125,Short,NASDAQ,10:00:00.165655,1180537 | not 100
​
What am I doing wrong here?
Thank you in advance for your insight(s).
https://redd.it/13oxjfs
@r_bash
Reddit
r/bash on Reddit: print $0 giving me unexpected result
Posted by u/rrk100 - No votes and 1 comment
HAVING ERROR IN FIRST CODE
Hello everyone so I started learning bash today and I am making a basic math calculator thorugh my VMware kali terminal. I dont know why but I am getting this error of line 35 error: syntax error near unexpected token ' echo "result: $result" '...Can anyone help me out? (Attaching my code below)
ALSO in my code image if I remove single quotes it still shows error
https://preview.redd.it/akbma2u5kf1b1.png?width=412&format=png&auto=webp&v=enabled&s=76a7ac94a05cc9e0e11c8956e5358b43e516cd21
https://redd.it/13ozru9
@r_bash
Hello everyone so I started learning bash today and I am making a basic math calculator thorugh my VMware kali terminal. I dont know why but I am getting this error of line 35 error: syntax error near unexpected token ' echo "result: $result" '...Can anyone help me out? (Attaching my code below)
ALSO in my code image if I remove single quotes it still shows error
https://preview.redd.it/akbma2u5kf1b1.png?width=412&format=png&auto=webp&v=enabled&s=76a7ac94a05cc9e0e11c8956e5358b43e516cd21
https://redd.it/13ozru9
@r_bash
How to create Bash noscript that first checks if it's already running?
I've got an rsync noscript that is run daily, but often there is so much to back up it fires up another job when I want the original job to complete first.
I know a process id check can be used for this — can someone please direct me towards a tutorial or method on how to do that?
TIA!
https://redd.it/13p4osw
@r_bash
I've got an rsync noscript that is run daily, but often there is so much to back up it fires up another job when I want the original job to complete first.
I know a process id check can be used for this — can someone please direct me towards a tutorial or method on how to do that?
TIA!
https://redd.it/13p4osw
@r_bash
Reddit
r/bash on Reddit: How to create Bash noscript that first checks if it's already running?
Posted by u/lurch99 - No votes and 2 comments
Compare the differences between dirs and sync
I have two directories A (local) and B (Remote/SFTP). I would like to somehow sync them based to A.
I cant really rsync because A dir has plaintext files and B has encrypted files(GPG).
Example:
Local dir contains: A.txt, B.txt, D.txt, F.txt, G.txt
Remote dir contains: A.txt.gpg, B.txt.gpg, C.txt.gpg, D.txt.gpg, E.txt.gpg, F.txt.gpg
The result I need is remote dir to be like A.txt.gpg, B.txt.gpg, D.txt.gpg, F.txt.gpg, G.txt.gpg
Hence, the file G.txt will be transfer over and files C & F will be deleted from remote dir
P.S I have the functions ready to basebane fies, encrypt them, rsync them.
​
​
My question is how to compare the differences and run my functions accordingly?
What is coming to my mind is to create a array for each dir and compare but Im sure there is smarter and cleaner way than that. Any thoughts?
https://redd.it/13phrj7
@r_bash
I have two directories A (local) and B (Remote/SFTP). I would like to somehow sync them based to A.
I cant really rsync because A dir has plaintext files and B has encrypted files(GPG).
Example:
Local dir contains: A.txt, B.txt, D.txt, F.txt, G.txt
Remote dir contains: A.txt.gpg, B.txt.gpg, C.txt.gpg, D.txt.gpg, E.txt.gpg, F.txt.gpg
The result I need is remote dir to be like A.txt.gpg, B.txt.gpg, D.txt.gpg, F.txt.gpg, G.txt.gpg
Hence, the file G.txt will be transfer over and files C & F will be deleted from remote dir
P.S I have the functions ready to basebane fies, encrypt them, rsync them.
​
​
My question is how to compare the differences and run my functions accordingly?
What is coming to my mind is to create a array for each dir and compare but Im sure there is smarter and cleaner way than that. Any thoughts?
https://redd.it/13phrj7
@r_bash
Reddit
r/bash on Reddit: Compare the differences between dirs and sync
Posted by u/OscarCY - No votes and no comments
save - Capture and reuse output of command (Bash function)
https://gist.github.com/thingsiplay/612d2482b8747cf20e6bf4756d43eed4
https://redd.it/13pl4xs
@r_bash
https://gist.github.com/thingsiplay/612d2482b8747cf20e6bf4756d43eed4
https://redd.it/13pl4xs
@r_bash
Gist
save - Capture and reuse output of command (Bash function)
save - Capture and reuse output of command (Bash function) - save ()
A bash noscript for converting security camera recordings in
Received a video recording from a friend for checking a burglary event. Looking at the sdcard contents, there seems to be many folders with names like 1645645354 and contents with `.media` files. Turns out the file names are unix epoch and the `.media` files can be converted using `ffmpeg`. Wrote small noscript and tested on few thousand files. It might be useful for someone else:
https://github.com/IbrahimTanyalcin/camToMP4
MIT License, logo and comments by chatGPT
https://redd.it/13pm9x6
@r_bash
.media or similar format to .mp4/.mkvReceived a video recording from a friend for checking a burglary event. Looking at the sdcard contents, there seems to be many folders with names like 1645645354 and contents with `.media` files. Turns out the file names are unix epoch and the `.media` files can be converted using `ffmpeg`. Wrote small noscript and tested on few thousand files. It might be useful for someone else:
https://github.com/IbrahimTanyalcin/camToMP4
MIT License, logo and comments by chatGPT
https://redd.it/13pm9x6
@r_bash
GitHub
GitHub - IbrahimTanyalcin/cam-to-mp4: Convert and concatenate files from your surveillance camera to mp4/mkv
Convert and concatenate files from your surveillance camera to mp4/mkv - GitHub - IbrahimTanyalcin/cam-to-mp4: Convert and concatenate files from your surveillance camera to mp4/mkv
solaris 10 cron failed command substitution.
0,20,40 * * * bash -c -l /usr/local/monitors/lp_mon2
\#!/bin/bash
\#grab oldest file from queue
stuff=\`ls -1 /var/spool/lp/requests/localhost/ | /usr/bin/head -1\`
\#pull printer name from lp requests (first line in file)
puff=\`cat $stuff | /usr/bin/head -1 | sed -e 's/-.*//' -e 's/$/ is having issues printing from /'\`
if [ "$(ls -A /var/spool/lp/requests/localhost/)" ]
then
echo $puff | /usr/ucb/mail foo@bar.com
else
echo lp queue is empty | /usr/ucb/mail foo@bar.com
fi
Also tried:
stuff="(ls -1 /var/spool/lp/requests/localhost/ | /usr/bin/head -1)"
puff="$(cat $stuff | /usr/bin/head -1 | sed -e 's/-.*//' -e 's/$/ is having issues printing
Suggestions??
https://redd.it/13pq6d3
@r_bash
0,20,40 * * * bash -c -l /usr/local/monitors/lp_mon2
\#!/bin/bash
\#grab oldest file from queue
stuff=\`ls -1 /var/spool/lp/requests/localhost/ | /usr/bin/head -1\`
\#pull printer name from lp requests (first line in file)
puff=\`cat $stuff | /usr/bin/head -1 | sed -e 's/-.*//' -e 's/$/ is having issues printing from /'\`
if [ "$(ls -A /var/spool/lp/requests/localhost/)" ]
then
echo $puff | /usr/ucb/mail foo@bar.com
else
echo lp queue is empty | /usr/ucb/mail foo@bar.com
fi
Also tried:
stuff="(ls -1 /var/spool/lp/requests/localhost/ | /usr/bin/head -1)"
puff="$(cat $stuff | /usr/bin/head -1 | sed -e 's/-.*//' -e 's/$/ is having issues printing
Suggestions??
https://redd.it/13pq6d3
@r_bash
Reddit
r/bash on Reddit: solaris 10 cron failed command substitution.
Posted by u/dam_broke_it_again - No votes and 1 comment
how to prevent this variable form becoming equal to when directory is empty
list=$(for f in "$dir"/\ ; do printf '%s\\n' "$(basename $f)" ; done )
works as expected when the directory is not empty but when it's empty, it becomes equal to * and I want it to become an empty string if the directory is empty
https://redd.it/13q28rv
@r_bash
list=$(for f in "$dir"/\ ; do printf '%s\\n' "$(basename $f)" ; done )
works as expected when the directory is not empty but when it's empty, it becomes equal to * and I want it to become an empty string if the directory is empty
https://redd.it/13q28rv
@r_bash
Reddit
r/bash on Reddit: how to prevent this variable form becoming equal to * when directory is empty
Posted by u/Aeul289 - No votes and no comments
Simple file path opening code
I’m as new as you can get to using bash and was trying to make a little code to make some of my work tasks easier. I’ve just been saving a .txt file as .bat and double clicking when I need to use it.
I figured out how to use explorer to open the file path I want, but now I want it to be a little smarter. Say I have the file path:
T:\Files\Reports
I figured how to open it using “explorer” but now I want to add the month after and have it change to the current month accordingly. For example, this month would be:
explorer T:\Files\Reports\04
I have found multiple things online on how to get current date and how to concatenate strings, but “explorer” doesn’t seem to accept a variable as a useable path. I’m not sure about many of the rules of bash code and all it’s intricacies, so I was hoping someone here could help me. Thanks!!
https://redd.it/13qoinl
@r_bash
I’m as new as you can get to using bash and was trying to make a little code to make some of my work tasks easier. I’ve just been saving a .txt file as .bat and double clicking when I need to use it.
I figured out how to use explorer to open the file path I want, but now I want it to be a little smarter. Say I have the file path:
T:\Files\Reports
I figured how to open it using “explorer” but now I want to add the month after and have it change to the current month accordingly. For example, this month would be:
explorer T:\Files\Reports\04
I have found multiple things online on how to get current date and how to concatenate strings, but “explorer” doesn’t seem to accept a variable as a useable path. I’m not sure about many of the rules of bash code and all it’s intricacies, so I was hoping someone here could help me. Thanks!!
https://redd.it/13qoinl
@r_bash
Reddit
r/bash on Reddit: Simple file path opening code
Posted by u/JCat43 - No votes and 1 comment
Script not working like we had envisioned it working
I've been working with ChatGPT to create a noscript that iterates through my entire music library, looking for filenames that are like "<##> - <Artist> - <Title>", and renaming them as "<##> <Title>". I still need to add a couple conventions, like "<##>. <Artist> - <Title>" and such, but the problem is that it's currently not doing what it should, leaving filenames as "<##> - <Title>" or just leaving the filename completely unchanged. It's also supposed to add a leading zero to the track number in the filename if it's 's a single digit. It's not doing that, either. We've been working at this for a couple hours trying to figure out why it's not doing the thing. Here's the noscript. Edit: Forgot to "ask a question", so, Can you help me? Edit 2: Oh, by the way, I know the music_library path is set to '/path/to/music/library' I do have it set properly on my system. Edit 3: left out a bit of what it's supposed to do.
https://redd.it/13qq0wr
@r_bash
I've been working with ChatGPT to create a noscript that iterates through my entire music library, looking for filenames that are like "<##> - <Artist> - <Title>", and renaming them as "<##> <Title>". I still need to add a couple conventions, like "<##>. <Artist> - <Title>" and such, but the problem is that it's currently not doing what it should, leaving filenames as "<##> - <Title>" or just leaving the filename completely unchanged. It's also supposed to add a leading zero to the track number in the filename if it's 's a single digit. It's not doing that, either. We've been working at this for a couple hours trying to figure out why it's not doing the thing. Here's the noscript. Edit: Forgot to "ask a question", so, Can you help me? Edit 2: Oh, by the way, I know the music_library path is set to '/path/to/music/library' I do have it set properly on my system. Edit 3: left out a bit of what it's supposed to do.
https://redd.it/13qq0wr
@r_bash
GitHub
Projects/mus_lib_rename.sh at main · darth-crunchus/Projects
Just random projects I'm working on. Contribute to darth-crunchus/Projects development by creating an account on GitHub.
Two-Way File <-> FileList Check
Hello, this bash noscript will loop through lines of files from FileList.txt and check if a directory contains such file... Now I want to do it the other way, loop through a directory and check if filename exists in the FileList.txt . How do I do it? Files may contain special characters...
#!/usr/bin/env bash
#Check Files in list from file exist or doesn't exist in directory.
if $# -eq 0 || $# -eq 1
then
echo "You must pass the path to file with the list and the path to directory to check files. \nsh check-file-exist-from-list.sh path/to/file path/to/directory"
exit 1
fi
while read -r file; do
if -e "$2/$file" ; then
echo "$file exists in $2"
else
echo "$file doesn't exist in $2"
fi
done < "$1"
https://redd.it/13qwd06
@r_bash
Hello, this bash noscript will loop through lines of files from FileList.txt and check if a directory contains such file... Now I want to do it the other way, loop through a directory and check if filename exists in the FileList.txt . How do I do it? Files may contain special characters...
#!/usr/bin/env bash
#Check Files in list from file exist or doesn't exist in directory.
if $# -eq 0 || $# -eq 1
then
echo "You must pass the path to file with the list and the path to directory to check files. \nsh check-file-exist-from-list.sh path/to/file path/to/directory"
exit 1
fi
while read -r file; do
if -e "$2/$file" ; then
echo "$file exists in $2"
else
echo "$file doesn't exist in $2"
fi
done < "$1"
https://redd.it/13qwd06
@r_bash
Reddit
r/bash on Reddit: Two-Way File <-> FileList Check
Posted by u/ajkcmkla - No votes and no comments
I have a weird
I can't remember what I was trying to do, I think I modified something in JAVA_HOME and since then I broke everything.
Brew doesn't work anymore, the custom color scheme I had for the terminal is gone and I always get this error
​
https://preview.redd.it/grw8emfl8u1b1.png?width=1884&format=png&auto=webp&v=enabled&s=16b1fae9a35417301bcba8c9f2301b4cdc9672bd
It says there is an unexpected token ) in line 1, but there's none there
​
https://preview.redd.it/128o2qaq8u1b1.png?width=1972&format=png&auto=webp&v=enabled&s=7da6270a482d9077cae6ec3aee0875405ba46b1e
As you can see here. I am a complete noob with bash and I had a friend set up brew and other neat tools for me, I tried to find a solution myself for days, but I can't for the life of me understand what is going on.. can someone help me?
https://redd.it/13qwmpo
@r_bash
Syntax error near unexpected token ")"I can't remember what I was trying to do, I think I modified something in JAVA_HOME and since then I broke everything.
Brew doesn't work anymore, the custom color scheme I had for the terminal is gone and I always get this error
​
https://preview.redd.it/grw8emfl8u1b1.png?width=1884&format=png&auto=webp&v=enabled&s=16b1fae9a35417301bcba8c9f2301b4cdc9672bd
It says there is an unexpected token ) in line 1, but there's none there
​
https://preview.redd.it/128o2qaq8u1b1.png?width=1972&format=png&auto=webp&v=enabled&s=7da6270a482d9077cae6ec3aee0875405ba46b1e
As you can see here. I am a complete noob with bash and I had a friend set up brew and other neat tools for me, I tried to find a solution myself for days, but I can't for the life of me understand what is going on.. can someone help me?
https://redd.it/13qwmpo
@r_bash