Question regarding Logrotate
Hi all, I am trying to understand logrotate on my linux servers. I have read all the docs on it and how we use individual config files to control other app logs. My question is does the logrotate.conf set a precedence over the files in logrotate.d directory? I would also like to know can you do away with the files in the logrotate.d directory and just put all the info in the logrotate.conf file? Thanks any other helpful info would be appreciated as well.
https://redd.it/12cp7q1
@r_bash
Hi all, I am trying to understand logrotate on my linux servers. I have read all the docs on it and how we use individual config files to control other app logs. My question is does the logrotate.conf set a precedence over the files in logrotate.d directory? I would also like to know can you do away with the files in the logrotate.d directory and just put all the info in the logrotate.conf file? Thanks any other helpful info would be appreciated as well.
https://redd.it/12cp7q1
@r_bash
Reddit
r/bash on Reddit: Question regarding Logrotate
Posted by u/Individual-Self-9533 - No votes and no comments
zsh-style menu completion in bash?
Is there any way to get zsh-style tab menu completion in bash? Specifically, where the list of completions appears, you can tab through them, and once you've selected it the menu disappears? https://asciinema.org/a/2q4M7y9cu476xrlK6TLfCZlJg
https://redd.it/12cqxxl
@r_bash
Is there any way to get zsh-style tab menu completion in bash? Specifically, where the list of completions appears, you can tab through them, and once you've selected it the menu disappears? https://asciinema.org/a/2q4M7y9cu476xrlK6TLfCZlJg
https://redd.it/12cqxxl
@r_bash
asciinema.org
unnoscriptd
Recorded by dmd3eorg
Automating unzipping files in multiple sub folders
Hello Everyone,
I'm planning on how to write this bash noscript.
I currently have a parent directory called 'logs' containing sub-folders that populate once daily with the current dates. In these sub-folders are .csv.gzip files that I need to unzip. I want to automate the process by creating a cron job to run this bash noscript. I'm new to bash noscripting, so please bare with me.
Can anyone point me to resources that best explain how to accomplish this?
I think iterating using a for loop into each sub-folder and then having an if statement to check if it contains the .csv.gzip file extension and if the value is true to unzip the files. Then, move to the next sub-folder.
All the sub-folders have this format YYYY-MM-DD.
Any help would be greatly appreciated.
https://redd.it/12cxwba
@r_bash
Hello Everyone,
I'm planning on how to write this bash noscript.
I currently have a parent directory called 'logs' containing sub-folders that populate once daily with the current dates. In these sub-folders are .csv.gzip files that I need to unzip. I want to automate the process by creating a cron job to run this bash noscript. I'm new to bash noscripting, so please bare with me.
Can anyone point me to resources that best explain how to accomplish this?
I think iterating using a for loop into each sub-folder and then having an if statement to check if it contains the .csv.gzip file extension and if the value is true to unzip the files. Then, move to the next sub-folder.
All the sub-folders have this format YYYY-MM-DD.
Any help would be greatly appreciated.
https://redd.it/12cxwba
@r_bash
Reddit
r/bash on Reddit: Automating unzipping files in multiple sub folders
Posted by u/No_B0dyCares - No votes and no comments
YAD noscript help.....A progress bar without error window
I'm having issues implementing an error window that stops the progress and shows what failed. currently, the window will continue regardless of the error.
code is :
\#!/bin/bash -f
\#log not working
log="/home/pi/yad/logs/Rut_Check_error.log > $(date +'%FT%T%Z')"
(
\# =================================================================
echo "5"
echo "# Varifying Data Is correct." ; sleep 3
\## Calling exp. noscript
./Print_Qr_exp.sh && tail
\# =================================================================
echo "25"
echo "# Collecting Rut Infomation." ; sleep 2
grep "Mac," Rut-Info.log | tr ',' '\\n' | tail -n1 > mac.log
\# =================================================================
echo "55"
echo "# Getting the printer ready." ; sleep 3
\# Script runs Python env and prints
./activ.sh
\# =================================================================
echo "85"
echo "# Storing data logs" ; sleep 4
\## mv rut-info.txt (rename it to date) ; mv inst.log (rename with date) into new folder
\# =================================================================
echo "100"
echo "# Successful" ; sleep 1
) |
yad --progress --center --borders=70 \\
\--width=850 --height=650 \\
\--noscript="#### Progress Status ####" \\
\--text="Processing Data In Session." \\
\--text-align=center \\
\--percentage=0 \\
\--auto-kill \\
\#--auto-close \\
(( $? != 0)) && yad --error --text="Error in yad command." --width="400" --height="400" --noscript="Error Data"\\
exit 1
https://redd.it/12czvv6
@r_bash
I'm having issues implementing an error window that stops the progress and shows what failed. currently, the window will continue regardless of the error.
code is :
\#!/bin/bash -f
\#log not working
log="/home/pi/yad/logs/Rut_Check_error.log > $(date +'%FT%T%Z')"
(
\# =================================================================
echo "5"
echo "# Varifying Data Is correct." ; sleep 3
\## Calling exp. noscript
./Print_Qr_exp.sh && tail
\# =================================================================
echo "25"
echo "# Collecting Rut Infomation." ; sleep 2
grep "Mac," Rut-Info.log | tr ',' '\\n' | tail -n1 > mac.log
\# =================================================================
echo "55"
echo "# Getting the printer ready." ; sleep 3
\# Script runs Python env and prints
./activ.sh
\# =================================================================
echo "85"
echo "# Storing data logs" ; sleep 4
\## mv rut-info.txt (rename it to date) ; mv inst.log (rename with date) into new folder
\# =================================================================
echo "100"
echo "# Successful" ; sleep 1
) |
yad --progress --center --borders=70 \\
\--width=850 --height=650 \\
\--noscript="#### Progress Status ####" \\
\--text="Processing Data In Session." \\
\--text-align=center \\
\--percentage=0 \\
\--auto-kill \\
\#--auto-close \\
(( $? != 0)) && yad --error --text="Error in yad command." --width="400" --height="400" --noscript="Error Data"\\
exit 1
https://redd.it/12czvv6
@r_bash
Reddit
r/bash on Reddit: YAD noscript help.....A progress bar without error window
Posted by u/Queasy_Piece5446 - No votes and 2 comments
smarter way to test bash noscripts and list all external commands
I was wondering if there were smart ways to find all uses of external commands in a bash noscript ?
i.e. is grep using built in bash or external grep etc (( can't think of a perfect command where its in both places at this time of night :P )).
The only solution in my head is strace or something but was wondering if there were a better way?
https://redd.it/12d2yhm
@r_bash
I was wondering if there were smart ways to find all uses of external commands in a bash noscript ?
i.e. is grep using built in bash or external grep etc (( can't think of a perfect command where its in both places at this time of night :P )).
The only solution in my head is strace or something but was wondering if there were a better way?
https://redd.it/12d2yhm
@r_bash
Reddit
r/bash on Reddit: smarter way to test bash noscripts and list all external commands
Posted by u/daz_007 - No votes and no comments
quote help
I am trying to build information for my bash prompt. The following command works in the terminal.
git worktree list 2>/dev/null | grep -v "^${HOME} " | sed -e 's/^.\[//' -e 's/\]$//'
When I add this to .bashrc, I get an error stating the following:
grep: ": No such file or directory
This is the line in the .bashrc file
PS1="${PS1}$(git worktree list 2>/dev/null | grep -v \"^${HOME} \" | sed -e 's/^.[//' -e 's/\]$//')"
https://redd.it/12dgc05
@r_bash
I am trying to build information for my bash prompt. The following command works in the terminal.
git worktree list 2>/dev/null | grep -v "^${HOME} " | sed -e 's/^.\[//' -e 's/\]$//'
When I add this to .bashrc, I get an error stating the following:
grep: ": No such file or directory
This is the line in the .bashrc file
PS1="${PS1}$(git worktree list 2>/dev/null | grep -v \"^${HOME} \" | sed -e 's/^.[//' -e 's/\]$//')"
https://redd.it/12dgc05
@r_bash
Reddit
r/bash on Reddit: quote help
Posted by u/linux478 - No votes and 3 comments
Optimizing bash noscripts?
How? I've read somewhere over the Internet that the *sh family is inherently slow. How could we reduce the impact of this nature so that bash noscripts can perform faster? Are there recommended habits to follow? Hints? Is there any primordial advice?
https://redd.it/12drpy9
@r_bash
How? I've read somewhere over the Internet that the *sh family is inherently slow. How could we reduce the impact of this nature so that bash noscripts can perform faster? Are there recommended habits to follow? Hints? Is there any primordial advice?
https://redd.it/12drpy9
@r_bash
Reddit
r/bash on Reddit: Optimizing bash noscripts?
Posted by u/Mark_1802 - No votes and 8 comments
Can someone explain how [:print:] works?
So one of the noscript is:
echo /sys/devices/pci0000:00/0000:00:14.0/i2c-4/4-002e/hwmon/hwmon[[:print:\]\]*/pwm2
I understand the result, but how does it work? What is it call in bash?
https://redd.it/12du8ed
@r_bash
So one of the noscript is:
echo /sys/devices/pci0000:00/0000:00:14.0/i2c-4/4-002e/hwmon/hwmon[[:print:\]\]*/pwm2
I understand the result, but how does it work? What is it call in bash?
https://redd.it/12du8ed
@r_bash
Reddit
r/bash on Reddit: Can someone explain how [[:print:]] works?
Posted by u/paulsiu - No votes and no comments
Checkbox menu without whiptail or dialog
I'm wanting to write a menu with checkboxes in bash. Installing whiptail or dialog are not options.
Is it even possible to a menu with checkboxes in bash without whiptail or dialog?
https://redd.it/12e8hbl
@r_bash
I'm wanting to write a menu with checkboxes in bash. Installing whiptail or dialog are not options.
Is it even possible to a menu with checkboxes in bash without whiptail or dialog?
https://redd.it/12e8hbl
@r_bash
Reddit
r/bash on Reddit: Checkbox menu without whiptail or dialog
Posted by u/DaveR007 - No votes and no comments
What am I doing wrong?
the noscript:
find /path/to/folder -type f \\( -iname "*.flac" -o -iname "*.wav" -o -iname "*.alac" -o -iname "*.aiff" -o -iname "*.ape" -o -iname "*.dsd" \\) -o -iname "*.mp3" -exec bash -c '
for audio_file do
audio_basename="$(basename "${audio_file}")"
target_file="/path/to/tracks/${audio_basename%.*}.flac"
[[ -f "${target_file}" \]\] && continue
lossless_file=""
for ext in flac alac wav aiff ape dsd; do
lf="${audio_file%.*}.${ext}"
[[ -f "${lf}" \]\] && lossless_file="${lf}" && break
done
[[ -z "${lossless_file}" \]\] && lossless_file="${audio_file}"
mp3_file="${audio_file%.*}.mp3"
if [[ -f "${mp3_file}" && "${lossless_file}" != "${audio_file}" \]\]; then
mtime_mp3="$(stat -f '%m' "${mp3_file}")"
mtime_lossless="$(stat -f '%m' "${lossless_file}")"
if [[ "${mtime_mp3}" -gt "${mtime_lossless}" \]\]; then
lossless_file="${mp3_file}"
fi
fi
cp -n "${lossless_file}" "${target_file}"
done' bash {} +
It should comb through a folder structure with audio files and copy them to a new folder. If there are two files with the same name it should prioritise the lossless format. When i run the noscript, I only get files with .flac format in the new folder. What am I missing?
https://redd.it/12eouk3
@r_bash
the noscript:
find /path/to/folder -type f \\( -iname "*.flac" -o -iname "*.wav" -o -iname "*.alac" -o -iname "*.aiff" -o -iname "*.ape" -o -iname "*.dsd" \\) -o -iname "*.mp3" -exec bash -c '
for audio_file do
audio_basename="$(basename "${audio_file}")"
target_file="/path/to/tracks/${audio_basename%.*}.flac"
[[ -f "${target_file}" \]\] && continue
lossless_file=""
for ext in flac alac wav aiff ape dsd; do
lf="${audio_file%.*}.${ext}"
[[ -f "${lf}" \]\] && lossless_file="${lf}" && break
done
[[ -z "${lossless_file}" \]\] && lossless_file="${audio_file}"
mp3_file="${audio_file%.*}.mp3"
if [[ -f "${mp3_file}" && "${lossless_file}" != "${audio_file}" \]\]; then
mtime_mp3="$(stat -f '%m' "${mp3_file}")"
mtime_lossless="$(stat -f '%m' "${lossless_file}")"
if [[ "${mtime_mp3}" -gt "${mtime_lossless}" \]\]; then
lossless_file="${mp3_file}"
fi
fi
cp -n "${lossless_file}" "${target_file}"
done' bash {} +
It should comb through a folder structure with audio files and copy them to a new folder. If there are two files with the same name it should prioritise the lossless format. When i run the noscript, I only get files with .flac format in the new folder. What am I missing?
https://redd.it/12eouk3
@r_bash
Reddit
r/bash on Reddit: What am I doing wrong?
Posted by u/lucidgazorpazorp - No votes and no comments
search and replace (if not equal)
I am hoping someone can help
I need to create a simple bash noscript
read through /etc/hosts
if IP does not equal "X.X.X.X" then rename it to Y.Y.Y.Y
I can run that whenever I would like and just change the IPs as necessary
Similarly, I want to do the same with printers.conf with a twist
if printer name starts with A, then change IP to X.X.X.X if printer name starts with B then change IP to Y.Y.Y.Y
Can anyone help with that, please
thank you
https://redd.it/12ex3mq
@r_bash
I am hoping someone can help
I need to create a simple bash noscript
read through /etc/hosts
if IP does not equal "X.X.X.X" then rename it to Y.Y.Y.Y
I can run that whenever I would like and just change the IPs as necessary
Similarly, I want to do the same with printers.conf with a twist
if printer name starts with A, then change IP to X.X.X.X if printer name starts with B then change IP to Y.Y.Y.Y
Can anyone help with that, please
thank you
https://redd.it/12ex3mq
@r_bash
Reddit
r/bash on Reddit: search and replace (if not equal)
Posted by u/runningonempty999 - No votes and no comments
Properly attach tmux session Jupyter Lab
Lately I have been running long Python noscripts in Jupyter lab on a remote server. However, when the server disconnects for some reason I lose all the progress, and I need to start over. Sorry in advance, I'm really new to this so I might sound plain stupid.
So I learned that a work around for this is to use tmux, in which I operate a noscript in the background? However, I am having trouble with it.
So first I open the ssh connection with the server in bash. Then I create a new tmux session (I have no other tmux sessions). Then I type the python environment I want to use and jupyter lab to open it in the browser.
Okay so I am running all the cells and then de-attach the tmux using ctrl+b and d. All good (I assume).
But then when I disconnect, and then try to connect again by attaching the tmux, I only get the log info. How am I supposed to open Jupyter lab again properly? I cannot type in that window. (Excuse my ignorance)
Anyways, I have tried creating a new pane using 'ctrl+b and %' and typing in the environment and jupyter lab to open. And also another window. I also just used the link it provides in the log window. In all cases, when I go to the noscript, it is not running at all, and there is no output?? I don't understand what I really need to do, or what went wrong.
I've also lost so much time on this lol, so currently I am running my code in the middle of the night, with my laptop on, the old fashion way. I'm going to sleep in a bit hoping the server didn't disconnect. But I feel like there gotta be something I am missing or just doing wrong. Does anyone know? I can provide more information. Thanks for the help anyway!
https://redd.it/12f3tam
@r_bash
Lately I have been running long Python noscripts in Jupyter lab on a remote server. However, when the server disconnects for some reason I lose all the progress, and I need to start over. Sorry in advance, I'm really new to this so I might sound plain stupid.
So I learned that a work around for this is to use tmux, in which I operate a noscript in the background? However, I am having trouble with it.
So first I open the ssh connection with the server in bash. Then I create a new tmux session (I have no other tmux sessions). Then I type the python environment I want to use and jupyter lab to open it in the browser.
Okay so I am running all the cells and then de-attach the tmux using ctrl+b and d. All good (I assume).
But then when I disconnect, and then try to connect again by attaching the tmux, I only get the log info. How am I supposed to open Jupyter lab again properly? I cannot type in that window. (Excuse my ignorance)
Anyways, I have tried creating a new pane using 'ctrl+b and %' and typing in the environment and jupyter lab to open. And also another window. I also just used the link it provides in the log window. In all cases, when I go to the noscript, it is not running at all, and there is no output?? I don't understand what I really need to do, or what went wrong.
I've also lost so much time on this lol, so currently I am running my code in the middle of the night, with my laptop on, the old fashion way. I'm going to sleep in a bit hoping the server didn't disconnect. But I feel like there gotta be something I am missing or just doing wrong. Does anyone know? I can provide more information. Thanks for the help anyway!
https://redd.it/12f3tam
@r_bash
Reddit
r/bash on Reddit: Properly attach tmux session Jupyter Lab
Posted by u/augusts99 - No votes and no comments
yt-dlp file name variable
Hello I am unable to get the file name created in the previous line by yt-dlp. I guess I could slice it when I input the url but I would like to build on this noscript later to do be able to handle whole playlists. Hoping a bash wizard out there has a good solution. Thank you.
​
#! /bin/bash
timestamp=$(date +%Y-%m-%d:%H:%M)
echo "enter youtube url"
read url
yt-dlp "$url" --list-formats
echo $file
echo "Enter the resolution of the clip or leave blank for audio only"
read res
# Uses || logical operator that should the first command fail runs the second one to only get audio.
yt-dlp -f "bvheight=$res+ba" "$url" -o '%(id)s.%(ext)s' || yt-dlp -f "ba" "$url" -o '%(id)s.audio.%(ext)s'
# can not get the file name created in line 14
ffmpeg -i "$%(id)s.audio.webm" -c:a libvorbis -b:a 64k "$file.audio.ogg"
https://redd.it/12frno2
@r_bash
Hello I am unable to get the file name created in the previous line by yt-dlp. I guess I could slice it when I input the url but I would like to build on this noscript later to do be able to handle whole playlists. Hoping a bash wizard out there has a good solution. Thank you.
​
#! /bin/bash
timestamp=$(date +%Y-%m-%d:%H:%M)
echo "enter youtube url"
read url
yt-dlp "$url" --list-formats
echo $file
echo "Enter the resolution of the clip or leave blank for audio only"
read res
# Uses || logical operator that should the first command fail runs the second one to only get audio.
yt-dlp -f "bvheight=$res+ba" "$url" -o '%(id)s.%(ext)s' || yt-dlp -f "ba" "$url" -o '%(id)s.audio.%(ext)s'
# can not get the file name created in line 14
ffmpeg -i "$%(id)s.audio.webm" -c:a libvorbis -b:a 64k "$file.audio.ogg"
https://redd.it/12frno2
@r_bash
Reddit
r/bash on Reddit: yt-dlp file name variable
Posted by u/Admirable_Mistake832 - No votes and no comments
what am I doing wrong
This is a function that will install a window manager based on a ps3 prompt
these are the variables
#wm's (wms_inst)
PS3="Would you like to install any's: "
options=("SpectrWM" "CWM" "Qtile" "Hyprland" "AwesomeWM" "Skip")
this is the function
#installs window managers
wms_inst () {
select opt in "${options[@]}"
while True
do
case $opt in
"SpectrWM", "spectrWM", "Spectrwm", "spectrwm")
nix-env -iA nixpkgs.spectrwm
;;
"CWM", "cWM", "Cwm", "cwm")
nix-env -iA nixpkgs.cwm
;;
"Qtile", "qtile")
nix-env -iA nixpkgs.qtile
;;
"Hyprland", "hyprland")
nix-env -iA nixpkgs.hyprland
;;
"AwesomeWM", "awesomeWM", "Awesomewm")
nix-env -iA nixpkgs.awesome
;;
"Skip", "skip")
read -p "Do you want to select another Y/N " wmselect;
if [ "$wmselect" = "y" ]; then
done
fi
;;
*) echo "invalid option";;
esac
done
}
It is failing at this part
`select opt in "${options[@]}"
while True
do`
there is an error with the select and the while loop but I cannot figure it out.
does anyone know the answer?
https://redd.it/12fst5l
@r_bash
This is a function that will install a window manager based on a ps3 prompt
these are the variables
#wm's (wms_inst)
PS3="Would you like to install any's: "
options=("SpectrWM" "CWM" "Qtile" "Hyprland" "AwesomeWM" "Skip")
this is the function
#installs window managers
wms_inst () {
select opt in "${options[@]}"
while True
do
case $opt in
"SpectrWM", "spectrWM", "Spectrwm", "spectrwm")
nix-env -iA nixpkgs.spectrwm
;;
"CWM", "cWM", "Cwm", "cwm")
nix-env -iA nixpkgs.cwm
;;
"Qtile", "qtile")
nix-env -iA nixpkgs.qtile
;;
"Hyprland", "hyprland")
nix-env -iA nixpkgs.hyprland
;;
"AwesomeWM", "awesomeWM", "Awesomewm")
nix-env -iA nixpkgs.awesome
;;
"Skip", "skip")
read -p "Do you want to select another Y/N " wmselect;
if [ "$wmselect" = "y" ]; then
done
fi
;;
*) echo "invalid option";;
esac
done
}
It is failing at this part
`select opt in "${options[@]}"
while True
do`
there is an error with the select and the while loop but I cannot figure it out.
does anyone know the answer?
https://redd.it/12fst5l
@r_bash
Reddit
r/bash on Reddit: what am I doing wrong
Posted by u/04AE - No votes and 1 comment
Need to unhide output
I have an embedded system I'm poking around in and from what I gather it's running bash. I'm taking a wild guess based on looking through the firmware.
I can get out of the application and drop to a shell however the following happens: blinking cursor, can type anything but when I hit enter it drops the blinking cursor to a new line and no output from the command is posted to the screen.
Using the Up, down, left, right keys produce characters such as, "^[D" when the left key is pressed, etc.
CTRL +ALT + DEL restarts the machine.
Enter moves the blinking cursor to the next line.
ESC produces "^[".
Tab works and moves the cursor over like it would in Windows.
What I'm looking for is a way to get the terminal/she'll to echo the output of the command or show the command prompt so I can see what's going on.
Any ideas? Excuse me if I'm in the wrong sub.
[https://redd.it/12g1knv
@r_bash
I have an embedded system I'm poking around in and from what I gather it's running bash. I'm taking a wild guess based on looking through the firmware.
I can get out of the application and drop to a shell however the following happens: blinking cursor, can type anything but when I hit enter it drops the blinking cursor to a new line and no output from the command is posted to the screen.
Using the Up, down, left, right keys produce characters such as, "^[D" when the left key is pressed, etc.
CTRL +ALT + DEL restarts the machine.
Enter moves the blinking cursor to the next line.
ESC produces "^[".
Tab works and moves the cursor over like it would in Windows.
What I'm looking for is a way to get the terminal/she'll to echo the output of the command or show the command prompt so I can see what's going on.
Any ideas? Excuse me if I'm in the wrong sub.
[https://redd.it/12g1knv
@r_bash
Reddit
r/bash on Reddit: Need to unhide output
Posted by u/patg84 - No votes and no comments
confusion over read ...or maybe printf?
So I'm doing some synthetic testing in order to better understand how read works, but now I think I'm getting tripped up with how printf works? The only thing I know for certain is I am confused.
I'm feeding the two arguments
bash-5.2$ read readitem < <(printf '%s\t%s\n' 'hello\' 'world') && echo "$readitem"
hello world
The \\t escape sequence is seemingly not negated, and the '\\' escape character itself is gone. Compare this to negating a newline in the format
bash-5.2$ read readitem < <(printf '%s\n%s\n' 'hello\' 'world') && echo "$readitem"
helloworld
And it works as I expect, with the
https://redd.it/12g8wvz
@r_bash
So I'm doing some synthetic testing in order to better understand how read works, but now I think I'm getting tripped up with how printf works? The only thing I know for certain is I am confused.
I'm feeding the two arguments
'hello\' 'world' to printf with the format %s\t%s\n. The 'hello\\' is deliberate as to negate the '\\t' escape sequence. The input stream is fed into the read command and I echo the variable. I'm expecting this to be pretty straight forward, with the output being something like 'helloworld', wherein the tab has been negated and the string is without any whitespace. After which I was expecting to add the -r option to read and see something like hello\ world because the backslash would be ignored as an escape character. When I actually run the command though...bash-5.2$ read readitem < <(printf '%s\t%s\n' 'hello\' 'world') && echo "$readitem"
hello world
The \\t escape sequence is seemingly not negated, and the '\\' escape character itself is gone. Compare this to negating a newline in the format
%s\n%s\n...bash-5.2$ read readitem < <(printf '%s\n%s\n' 'hello\' 'world') && echo "$readitem"
helloworld
And it works as I expect, with the
\n character being negated. Why am I able to escape the newline but not the tab?https://redd.it/12g8wvz
@r_bash
Reddit
r/bash on Reddit: confusion over read ...or maybe printf?
Posted by u/windows_sans_borders - No votes and 1 comment
bash returns me an error when reading a string with "/" from CSV file
This error `sed: -e expression #1, character 20: unknown option for s'` happens when `sed` reads a `/`.
I have a code that reads a CSV file, where there are cells with `/`. Here's a small portion of the code:
while read col1 col2
do
name1 = $col1 # here are cells that include "/"
name2 = $col2
for i in ${!name1[@]}
do
sed -i s/$name_place/"${name1[i]// /\\ }"/ file.noscript
# + more stuff here
done
done < $CSVfile
How can I fix it so the output includes the `/`?
https://redd.it/12gmok0
@r_bash
This error `sed: -e expression #1, character 20: unknown option for s'` happens when `sed` reads a `/`.
I have a code that reads a CSV file, where there are cells with `/`. Here's a small portion of the code:
while read col1 col2
do
name1 = $col1 # here are cells that include "/"
name2 = $col2
for i in ${!name1[@]}
do
sed -i s/$name_place/"${name1[i]// /\\ }"/ file.noscript
# + more stuff here
done
done < $CSVfile
How can I fix it so the output includes the `/`?
https://redd.it/12gmok0
@r_bash
Reddit
r/bash on Reddit: bash returns me an error when reading a string with "/" from CSV file
Posted by u/AlbertoAru - No votes and 2 comments