Help me understand the unclear language of the "locate" man, please
The command in question is "locate" in bash 3.2 on macOS. The fragments I have an issue with are the following:
> Shell globbing and quoting characters ('', ``?'', ``\'', ``['' and ``]'') may be used in pattern, although they will have to be escaped from the shell. Preceding any character with a backslash (``\'') eliminates any special meaning which it may have. The matching differs in that no characters must be matched explicitly, including slashes (``/'').
1. Since I haven't read man pages for a long time I forgot the symbolic meaning of the notation used. Why does the man page put double single quotes around these special characters? Are those the actual , ? ... or
2. Does the part saying that "they will have to be escaped from the shell" imply the double single quotes or the backlash character it brings in the next sentence?
3. "The matching differs in that no characters must be matched explicitly…": differs from what? "no chars must be matched explicitly" by whom or by what or in what context? Why "must" and not "have to"? What does "matched explicitly" mean? I can't have literal matches?
Another foggy excerpt is this:
> The 8-bit character support does not waste extra space for plain ASCII file names.
How is it "doesn't waste" and what would be it like if it did?
https://redd.it/zjk0un
@r_bash
The command in question is "locate" in bash 3.2 on macOS. The fragments I have an issue with are the following:
> Shell globbing and quoting characters ('', ``?'', ``\'', ``['' and ``]'') may be used in pattern, although they will have to be escaped from the shell. Preceding any character with a backslash (``\'') eliminates any special meaning which it may have. The matching differs in that no characters must be matched explicitly, including slashes (``/'').
1. Since I haven't read man pages for a long time I forgot the symbolic meaning of the notation used. Why does the man page put double single quotes around these special characters? Are those the actual , ? ... or
*'. ?' ...?2. Does the part saying that "they will have to be escaped from the shell" imply the double single quotes or the backlash character it brings in the next sentence?
3. "The matching differs in that no characters must be matched explicitly…": differs from what? "no chars must be matched explicitly" by whom or by what or in what context? Why "must" and not "have to"? What does "matched explicitly" mean? I can't have literal matches?
Another foggy excerpt is this:
> The 8-bit character support does not waste extra space for plain ASCII file names.
How is it "doesn't waste" and what would be it like if it did?
https://redd.it/zjk0un
@r_bash
reddit
Help me understand the unclear language of the "locate" man, please
The command in question is "locate" in bash 3.2 on macOS. The fragments I have an issue with are the following: > Shell globbing and quoting...
Having fun with bind shells and named pipes!
#!//usr/bin/bash
#BIND SHELL WITH NAMED PIPES
#CREATED BY: Zerodark875
fail() { ecode=${1};shift; 2>&1 echo "${*}";exit ${ecode};}
usage() { echo -e "Create bind shells using netcat and named pipes.\n\nUsage: $(basename ${0}) [port]\n\t[port]\t\tTCP Port number to listen on\n\t-h, --help\tThis Help Menu";fail 1;}
cleanup() { if [[ -e ${1} ]]; then echo "Cleaning up. Deleting ${1}"; rm -f ${1};fi;}
if [[ -z ${1} ]] || [[ ${1,,} == "-h" ]] || [[ ${1,,} == "--help" ]]; then
usage
fi
NP="/tmp/net_shell"
PORT=${1}
echo -n "Are you sure you want to start a bind shell on port ${PORT} (N/y):"
read choice
if [[ ${choice,,} == "n" ]]; then
fail 0 "Done."
fi
cleanup ${NP}
mkfifo ${NP} #make out named pipe!
echo "Starting bind shell on port ${PORT}"
cat ${NP} | $(which bash) -i 2>&1 | nc -nlp ${PORT} > ${NP}
cleanup ${NP}
echo "Done."
https://redd.it/zjql2p
@r_bash
#!//usr/bin/bash
#BIND SHELL WITH NAMED PIPES
#CREATED BY: Zerodark875
fail() { ecode=${1};shift; 2>&1 echo "${*}";exit ${ecode};}
usage() { echo -e "Create bind shells using netcat and named pipes.\n\nUsage: $(basename ${0}) [port]\n\t[port]\t\tTCP Port number to listen on\n\t-h, --help\tThis Help Menu";fail 1;}
cleanup() { if [[ -e ${1} ]]; then echo "Cleaning up. Deleting ${1}"; rm -f ${1};fi;}
if [[ -z ${1} ]] || [[ ${1,,} == "-h" ]] || [[ ${1,,} == "--help" ]]; then
usage
fi
NP="/tmp/net_shell"
PORT=${1}
echo -n "Are you sure you want to start a bind shell on port ${PORT} (N/y):"
read choice
if [[ ${choice,,} == "n" ]]; then
fail 0 "Done."
fi
cleanup ${NP}
mkfifo ${NP} #make out named pipe!
echo "Starting bind shell on port ${PORT}"
cat ${NP} | $(which bash) -i 2>&1 | nc -nlp ${PORT} > ${NP}
cleanup ${NP}
echo "Done."
https://redd.it/zjql2p
@r_bash
reddit
Having fun with bind shells and named pipes!
#!//usr/bin/bash #BIND SHELL WITH NAMED PIPES #CREATED BY: Zerodark875 fail() { ecode=${1};shift; 2>&1 echo "${*}";exit...
Add Header to csv file if no header is present
Hello!
What would be the best approach for trying to add header to a csv file, only if that file doesn’t contain the header?
What I was thinking was to get the first row, check wether it is the header, and if not add the header, but I am curious if there are other approaches.
Thanks in advance!
https://redd.it/zjqzj5
@r_bash
Hello!
What would be the best approach for trying to add header to a csv file, only if that file doesn’t contain the header?
What I was thinking was to get the first row, check wether it is the header, and if not add the header, but I am curious if there are other approaches.
Thanks in advance!
https://redd.it/zjqzj5
@r_bash
reddit
Add Header to csv file if no header is present
Hello! What would be the best approach for trying to add header to a csv file, only if that file doesn’t contain the header? What I was...
How to proper escape characters to to output string with color codes (non interpreted yet)?
Hi! I have the following code:
awk "{ print gensub(/\"(^ +)\"/, \"\\$(rawforeground magenta)\\\\1\\$(rawforeground none)\", \"g\") }" <<< ' "some" '
rawforeground() {
[[ -n "$2" ]] && {
corefunctionfailurewithinvalidargumenterror
return $FAILUREWITHINVALIDARGUMENT
}
declare colorname="$1"
declare -A colornameassociations=(
[none]=0
[black]=30
[red]=31
[green]=32
[yellow]=33
[blue]=34
[magenta]=35
[cyan]=36
[light-gray]=37
[gray]=90
[light-red]=91
[light-green]=92
[light-yellow]=93
[light-blue]=94
[light-magenta]=95
[light-cyan]=96
[white]=97
)
[[ ! -v colornameassociations[$colorname] ]] && {
corefunctionfailurewithinvalidargumentoutofrangeerror "${!colornameassociations[@]}"
return $FAILUREWITHINVALIDARGUMENTOUTOFRANGE
}
echo -n "\e[${colornameassociations[$colorname]}m"
}
I wanna replace
https://redd.it/zjxctf
@r_bash
Hi! I have the following code:
awk "{ print gensub(/\"(^ +)\"/, \"\\$(rawforeground magenta)\\\\1\\$(rawforeground none)\", \"g\") }" <<< ' "some" '
raw_foreground returns smth like \e[{{some-number}}m:rawforeground() {
[[ -n "$2" ]] && {
corefunctionfailurewithinvalidargumenterror
return $FAILUREWITHINVALIDARGUMENT
}
declare colorname="$1"
declare -A colornameassociations=(
[none]=0
[black]=30
[red]=31
[green]=32
[yellow]=33
[blue]=34
[magenta]=35
[cyan]=36
[light-gray]=37
[gray]=90
[light-red]=91
[light-green]=92
[light-yellow]=93
[light-blue]=94
[light-magenta]=95
[light-cyan]=96
[white]=97
)
[[ ! -v colornameassociations[$colorname] ]] && {
corefunctionfailurewithinvalidargumentoutofrangeerror "${!colornameassociations[@]}"
return $FAILUREWITHINVALIDARGUMENTOUTOFRANGE
}
echo -n "\e[${colornameassociations[$colorname]}m"
}
I wanna replace
"some" with "\e[45msome\e[0m" but I don't understand what I am missing now in the context of escaping characters.https://redd.it/zjxctf
@r_bash
reddit
How to proper escape characters to to output string with color...
Hi! I have the following code: awk "{ print gensub(/\"([^ ]+)\"/, \"\\$(raw_foreground magenta)\\\\1\\$(raw_foreground none)\", \"g\") }" <<<...
Testing if array elements are inside a string, not working when using *
Hi there
I'm stuck, tried a bunch of stuff & just can't work it out, would really appreciate some help!
I have an array, containing key words/phrases that can be contained in denoscription fields, if the denoscription field I'm handling contains one of these then I want to react in a certain way.
An example of my problem. I'm maybe misunderstanding how the [*\] bit works on arrays, don't know, but I'm expecting this to give the same results - as you can see, it doesn't! It looks like it should be so simple, & I really don't want to have to cycle through each element of the array 1 by 1:
Really appreciate any help!
https://redd.it/zk5yzk
@r_bash
Hi there
I'm stuck, tried a bunch of stuff & just can't work it out, would really appreciate some help!
I have an array, containing key words/phrases that can be contained in denoscription fields, if the denoscription field I'm handling contains one of these then I want to react in a certain way.
An example of my problem. I'm maybe misunderstanding how the [*\] bit works on arrays, don't know, but I'm expecting this to give the same results - as you can see, it doesn't! It looks like it should be so simple, & I really don't want to have to cycle through each element of the array 1 by 1:
# ignore_denoscription=("CHECK_NRPE" "Return code of 255" "Service check timed out after" "Plugin timed out" "(No output on stdout) stder" "(No output on stdout) stder")# denoscription="This is an example containing CHECK_NRPE just to test"# if [[ ${denoscription} =~ ${ignore_denoscription[0]} ]] ; then echo "it's there"; fiit's there# if [[ ${denoscription} =~ ${ignore_denoscription[*]} ]] ; then echo "it's there"; fi#Really appreciate any help!
https://redd.it/zk5yzk
@r_bash
reddit
Testing if array elements are inside a string, not working when...
Hi there I'm stuck, tried a bunch of stuff & just can't work it out, would really appreciate some help! I have an array, containing key...
Optimal par2 Switches for Mixed Data
I have compressed many files using bash find-exec tar.xz. I'd like to protect it for storage with ECCs. Data is mixed -- images, text, docs, html & associated folder .. & assorted media and zip files. I plan to create directories -- say, 1 to 10mb -- & compress. Then put each file in its own directory along with its ECCs.
find . -type f -name "*.tar.xz" -exec par2 create -s 1k -n 3 -r 10 "{}" ;
That's my noscript so far, guessing at appropriate block size, number of ECC files, & percent redundancy. I can't find good examples on how to set parameters with variant data. Suggestions much appreciated !!
https://redd.it/zk9zwe
@r_bash
I have compressed many files using bash find-exec tar.xz. I'd like to protect it for storage with ECCs. Data is mixed -- images, text, docs, html & associated folder .. & assorted media and zip files. I plan to create directories -- say, 1 to 10mb -- & compress. Then put each file in its own directory along with its ECCs.
find . -type f -name "*.tar.xz" -exec par2 create -s 1k -n 3 -r 10 "{}" ;
That's my noscript so far, guessing at appropriate block size, number of ECC files, & percent redundancy. I can't find good examples on how to set parameters with variant data. Suggestions much appreciated !!
https://redd.it/zk9zwe
@r_bash
reddit
Optimal par2 Switches for Mixed Data
I have compressed many files using bash find-exec tar.xz. I'd like to protect it for storage with ECCs. Data is mixed -- images, text, docs, html...
Help troubleshooting unexpected results from arrays in for loop.
I have a noscript that is triggered every hour by cron which runs through an array of functions and then outputs the code of the functions run, and the results to email. This is run on multiple hosts in multiple environments. My issue is that **randomly** when creating the results email, it changes the function(test\_str). So for instance, when I expect to see "CONDA\_FOLDER variable found \*\[ ! -z ${CONDA\_FOLDER} \]; return $?\*true", I will see something like "CONDA\_FOLDER variable found \*\[ ! -z ${ENV\_AUX} \]; return $?;\*true", or even "CONDA\_FOLDER variable found\*a() {\[ ! -z ${ENV} \]}\*true". What's really throwing my off is that it only happens sometimes. I think it has to do with variable expansion(s). But, I am apparently stuck spinning my wheels, so any help is really appreciated.
\#host\_diagnostic.sh
#!/bin/bash
run_folder=${HOME}/host_diagnostic
# Import array of functions
. ${run_folder}/tests.sh
echo "---------------------------------"
echo " Start Testing "
echo "---------------------------------"
for i in "${!funcs[@]}"
do
echo ${descs[$i]}
${funcs[$i]}
results+=($?)
done
echo "---------------------------------"
echo " Output Test Results "
echo "---------------------------------"
for i in "${!funcs[@]}"
do
test_name=${descs[$i]}
if [ ${results[$i]} != 0 ]
then
bool="false"
else
bool="true"
fi
#Get rid of the first and last two lines of the function, its extraneous data
declare -f "${funcs[$i]}" > func
num_lines=$(wc -l < func)
end="$((${num_lines}-2))"
beg="$((${end}-2))"
test_str="$(head -n ${end} func | tail -n ${beg} | xargs)"
echo -e "${test_name}*${test_str}*${bool}\n" >> "${out_file_name}"
echo -e "${test_name}*${test_str}*${bool}\n"
rm func
done
cat "${out_file_name}" | mail -s "${HOST} Capability Report" ${email}
rm "${out_file_name}"
echo "---------------------------------"
echo " Finished "
echo "---------------------------------"
tests.sh
funcs=()
descs=()
#Variables
db="app_db"
srv="server1"
timeout=2
user=$(${WHOAMI})
email="nunya@bidness.com"
out_file_name=${run_folder}/${HOST}.out
> ${out_file_name}
results=()
if [ -z "${ENV_AUX}" ]
then
env="${ENV}"
else
env="${ENV}-${ENV_AUX}"
fi
if [ "${env}" == "int" ]
then
sr_api_url="https://api.int.com"
else
sr_api_url="https://api-${env}.com"
fi
ip=$(ifconfig | grep -m 1 "inet" | awk '{print $2}')
####################################################################################
# Tests
####################################################################################
descs+=("ENV variable found")
funcs+=("a")
a()
{
[ ! -z ${ENV} ]
return $?
}
descs+=("ENV_AUX variable found")
funcs+=("b")
b()
{
[ ! -z ${ENV_AUX} ]
return $?
}
descs+=("COMMON_FOLDER variable found")
funcs+=("c")
c()
{
[ ! -z ${COMMON_FOLDER} ]
return $?
}
descs+=("Common folder found")
funcs+=("d")
d()
{
[ -d ${COMMON_FOLDER} ]
return $?
}
descs+=("CONDA_FOLDER variable found")
funcs+=("e")
e()
{
[ ! -z ${CONDA_FOLDER} ]
return $?
}
descs+=("Conda folder found")
funcs+=("f")
f()
{
[ -d ${CONDA_FOLDER} ]
return $?
}
descs+=("Kerberos initialized for user")
funcs+=("g")
g()
{
klist | grep -q "${user}"
return $?
}
descs+=("Crontab has correct entries")
funcs+=("h")
h()
{
I have a noscript that is triggered every hour by cron which runs through an array of functions and then outputs the code of the functions run, and the results to email. This is run on multiple hosts in multiple environments. My issue is that **randomly** when creating the results email, it changes the function(test\_str). So for instance, when I expect to see "CONDA\_FOLDER variable found \*\[ ! -z ${CONDA\_FOLDER} \]; return $?\*true", I will see something like "CONDA\_FOLDER variable found \*\[ ! -z ${ENV\_AUX} \]; return $?;\*true", or even "CONDA\_FOLDER variable found\*a() {\[ ! -z ${ENV} \]}\*true". What's really throwing my off is that it only happens sometimes. I think it has to do with variable expansion(s). But, I am apparently stuck spinning my wheels, so any help is really appreciated.
\#host\_diagnostic.sh
#!/bin/bash
run_folder=${HOME}/host_diagnostic
# Import array of functions
. ${run_folder}/tests.sh
echo "---------------------------------"
echo " Start Testing "
echo "---------------------------------"
for i in "${!funcs[@]}"
do
echo ${descs[$i]}
${funcs[$i]}
results+=($?)
done
echo "---------------------------------"
echo " Output Test Results "
echo "---------------------------------"
for i in "${!funcs[@]}"
do
test_name=${descs[$i]}
if [ ${results[$i]} != 0 ]
then
bool="false"
else
bool="true"
fi
#Get rid of the first and last two lines of the function, its extraneous data
declare -f "${funcs[$i]}" > func
num_lines=$(wc -l < func)
end="$((${num_lines}-2))"
beg="$((${end}-2))"
test_str="$(head -n ${end} func | tail -n ${beg} | xargs)"
echo -e "${test_name}*${test_str}*${bool}\n" >> "${out_file_name}"
echo -e "${test_name}*${test_str}*${bool}\n"
rm func
done
cat "${out_file_name}" | mail -s "${HOST} Capability Report" ${email}
rm "${out_file_name}"
echo "---------------------------------"
echo " Finished "
echo "---------------------------------"
tests.sh
funcs=()
descs=()
#Variables
db="app_db"
srv="server1"
timeout=2
user=$(${WHOAMI})
email="nunya@bidness.com"
out_file_name=${run_folder}/${HOST}.out
> ${out_file_name}
results=()
if [ -z "${ENV_AUX}" ]
then
env="${ENV}"
else
env="${ENV}-${ENV_AUX}"
fi
if [ "${env}" == "int" ]
then
sr_api_url="https://api.int.com"
else
sr_api_url="https://api-${env}.com"
fi
ip=$(ifconfig | grep -m 1 "inet" | awk '{print $2}')
####################################################################################
# Tests
####################################################################################
descs+=("ENV variable found")
funcs+=("a")
a()
{
[ ! -z ${ENV} ]
return $?
}
descs+=("ENV_AUX variable found")
funcs+=("b")
b()
{
[ ! -z ${ENV_AUX} ]
return $?
}
descs+=("COMMON_FOLDER variable found")
funcs+=("c")
c()
{
[ ! -z ${COMMON_FOLDER} ]
return $?
}
descs+=("Common folder found")
funcs+=("d")
d()
{
[ -d ${COMMON_FOLDER} ]
return $?
}
descs+=("CONDA_FOLDER variable found")
funcs+=("e")
e()
{
[ ! -z ${CONDA_FOLDER} ]
return $?
}
descs+=("Conda folder found")
funcs+=("f")
f()
{
[ -d ${CONDA_FOLDER} ]
return $?
}
descs+=("Kerberos initialized for user")
funcs+=("g")
g()
{
klist | grep -q "${user}"
return $?
}
descs+=("Crontab has correct entries")
funcs+=("h")
h()
{
while IFS= read -r line
do
if ! crontab -l | fgrep -q "${line}" > /dev/null 2>&1
then
return 1
fi
done < "${HOME}/app/${HOST}.com/crontabs.file"
return 0
}
descs+=("Crontab has correct host_diagnostic entries")
funcs+=("i")
i()
{
while IFS= read -r line
do
if ! crontab -l | fgrep -q "${line}" > /dev/null 2>&1
then
return 1
fi
done < "${HOME}/host_diagnostic/crontab_host_diagnostic.file"
return 0
}
descs+=("SQL server connectivity")
funcs+=("j")
j()
{
echo "SELECT @@SERVERNAME, @@VERSION GO" > temp_sql_func
sqlcmd -S "${srv}" -d "${db}" -i temp_sql_func -W -E | grep -q "(1 rows affected)"
result=$?
rm temp_sql_func
return ${result}
}
descs+=("App VIP connectivity")
funcs+=("k")
k()
{
curl --max-time ${timeout} "${sr_api_url}"
return $?
}
descs+=('ScriptRunner running at host address')
funcs+=("l")
l()
{
curl --max-time ${timeout} "${ip}" | grep -q "Network Error"
[ $? == 1 ]
return $?
}
https://redd.it/zkfufw
@r_bash
do
if ! crontab -l | fgrep -q "${line}" > /dev/null 2>&1
then
return 1
fi
done < "${HOME}/app/${HOST}.com/crontabs.file"
return 0
}
descs+=("Crontab has correct host_diagnostic entries")
funcs+=("i")
i()
{
while IFS= read -r line
do
if ! crontab -l | fgrep -q "${line}" > /dev/null 2>&1
then
return 1
fi
done < "${HOME}/host_diagnostic/crontab_host_diagnostic.file"
return 0
}
descs+=("SQL server connectivity")
funcs+=("j")
j()
{
echo "SELECT @@SERVERNAME, @@VERSION GO" > temp_sql_func
sqlcmd -S "${srv}" -d "${db}" -i temp_sql_func -W -E | grep -q "(1 rows affected)"
result=$?
rm temp_sql_func
return ${result}
}
descs+=("App VIP connectivity")
funcs+=("k")
k()
{
curl --max-time ${timeout} "${sr_api_url}"
return $?
}
descs+=('ScriptRunner running at host address')
funcs+=("l")
l()
{
curl --max-time ${timeout} "${ip}" | grep -q "Network Error"
[ $? == 1 ]
return $?
}
https://redd.it/zkfufw
@r_bash
reddit
Help troubleshooting unexpected results from arrays in for loop.
I have a noscript that is triggered every hour by cron which runs through an array of functions and then outputs the code of the functions run, and...
Automatically downloading links from RSS feed with Yotube-DL?
I need to do this but I don't know how. I can imagine this would be pretty easy to do with something like newsboat but I dont know the noscripting aspect. looking to do the same thing with gallery-dl as well but i can imagine if someone tells me how to do one i can figure out the other.
https://redd.it/zkho7x
@r_bash
I need to do this but I don't know how. I can imagine this would be pretty easy to do with something like newsboat but I dont know the noscripting aspect. looking to do the same thing with gallery-dl as well but i can imagine if someone tells me how to do one i can figure out the other.
https://redd.it/zkho7x
@r_bash
reddit
Automatically downloading links from RSS feed with Yotube-DL?
I need to do this but I don't know how. I can imagine this would be pretty easy to do with something like newsboat but I dont know the noscripting...
If you can't write awesome long noscripts, write a bunch of little ones. If you can't remember them all, you might like this one.
http://ix.io/4ixO
https://redd.it/zlb7ao
@r_bash
http://ix.io/4ixO
https://redd.it/zlb7ao
@r_bash
noobish type having trouble creating an executable file from a bash noscript. most answers are people trying to make a file executable after its written. id like to know how to make one while its written.
I'm 100% I'm just being dumb and missing the obvious, as I often do, so any help would be greatly and humbly received. I know how to create a file with permissions, I understand perfectly chmod +x and all the numbers you can use e.g. 700, all permissions to me and no users or groups. I know that 111 101 100 would be rwx/r-x/r-- or 754 etc. but what I'm having trouble with is writing a bash noscript that creates another executable bash noscript. This would be super handy for making test blank noscripts without going through the rigmarole of changing the permissions every time, be it through terminal or properties. I'm sure there's a way, but everything I've tried has failed. ive tried-
chmod +x; touch /filepath/noscript.sh
touch /filepath/noscript.sh; chmod +x
touch /filepath/noscript.sh && chmod +x
touch /filepath/noscript.sh chmod +x
touch /filepath/noscript.sh | chmod +x
i can't think of another way to try.
​
​
(these are just the basic ideas I've tried with numbers too in all the other variations)
I'd also love someone to point out why these aren't working i know why the bottom two dont work
https://redd.it/zlfqr4
@r_bash
I'm 100% I'm just being dumb and missing the obvious, as I often do, so any help would be greatly and humbly received. I know how to create a file with permissions, I understand perfectly chmod +x and all the numbers you can use e.g. 700, all permissions to me and no users or groups. I know that 111 101 100 would be rwx/r-x/r-- or 754 etc. but what I'm having trouble with is writing a bash noscript that creates another executable bash noscript. This would be super handy for making test blank noscripts without going through the rigmarole of changing the permissions every time, be it through terminal or properties. I'm sure there's a way, but everything I've tried has failed. ive tried-
chmod +x; touch /filepath/noscript.sh
touch /filepath/noscript.sh; chmod +x
touch /filepath/noscript.sh && chmod +x
touch /filepath/noscript.sh chmod +x
touch /filepath/noscript.sh | chmod +x
i can't think of another way to try.
​
​
(these are just the basic ideas I've tried with numbers too in all the other variations)
I'd also love someone to point out why these aren't working i know why the bottom two dont work
https://redd.it/zlfqr4
@r_bash
reddit
noobish type having trouble creating an executable file from a...
I'm 100% I'm just being dumb and missing the obvious, as I often do, so any help would be greatly and humbly received. I know how to create a file...
Working but not really
Hello! I'm trying to make the code in the link wok: https://www.geeksforgeeks.org/shell-noscript-to-scrap-the-definition-of-a-word-from-wikipedia/
​
However, even changing the syntax error of "fi", I still get no output. Anyone have an idea how to fix this
https://redd.it/zleno7
@r_bash
Hello! I'm trying to make the code in the link wok: https://www.geeksforgeeks.org/shell-noscript-to-scrap-the-definition-of-a-word-from-wikipedia/
​
However, even changing the syntax error of "fi", I still get no output. Anyone have an idea how to fix this
https://redd.it/zleno7
@r_bash
GeeksforGeeks
Shell Script to Scrap the Definition of a Word From Wikipedia - GeeksforGeeks
A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.
My kubectl bash noscript not working
I want to switch user to ansible when i exec into a k8s pod but my noscript is not working:
Kubectl exec -it -n $pod /bin/bash -c “su ansible && echo whoami”
https://redd.it/zlejyp
@r_bash
I want to switch user to ansible when i exec into a k8s pod but my noscript is not working:
Kubectl exec -it -n $pod /bin/bash -c “su ansible && echo whoami”
https://redd.it/zlejyp
@r_bash
reddit
My kubectl bash noscript not working
I want to switch user to ansible when i exec into a k8s pod but my noscript is not working: Kubectl exec -it -n $pod /bin/bash -c “su ansible &&...
Bash adding extra single quotes when running noscript
I'm making a noscript to convert mp4 to mkv while embedding subnoscripts but it doesn't work. If I am to put echo before mkverge on the last line and copy/paste the output into the terminal, it runs fine.
Here is a copy of the noscript:
#!/bin/bash
subfile=$(sed 's/mp4/eng.srt/' <<< "$1")
sdhsubfile=$(sed 's/mp4/eng.sdh.srt/' <<< "$1")
forcedsubfile=$(sed 's/mp4/eng.forced.srt/' <<< "$1")
outfile=$(sed 's/mp4/mkv/' <<< "$1")
if test -f "$subfile"; then
mainsrt='--track-name "0:English" --language "0:eng" '"$subfile"
fi
if test -f "$forcedsubfile"; then
forcedsrt='--track-name "0:English (Forced)" --language "0:eng" --forced-track "0:yes" --default-track "0:yes" '"$forcedsubfile"
fi
if test -f "$sdhsubfile"; then
sdhsrt='--track-name "0:English" --language "0:eng" "$subfile" --track-name "0:English (SDH)" --language "0:eng" '"$sdhsubfile"
fi
mkvmerge -o "$2/$outfile" "$1" "$mainsrt" "$forcedsrt" "$sdhsrt"
I added -x to the command so I could see the output and saw the following:
$ for i in *.mp4; do bash -x /noscripts/mp4_srt_to_mkv.sh "$i" "/home/username"; done
++ sed s/mp4/eng.srt/
+ subfile='Movie Name (2000) [Bluray-1080p-x265].eng.srt'
++ sed s/mp4/eng.sdh.srt/
+ sdhsubfile='Movie Name (2000) [Bluray-1080p-x265].eng.sdh.srt'
++ sed s/mp4/eng.forced.srt/
+ forcedsubfile='Movie Name (2000) [Bluray-1080p-x265].eng.forced.srt'
++ sed s/mp4/mkv/
+ outfile='Movie Name (2000) [Bluray-1080p-x265].mkv'
+ test -f 'Movie Name (2000) [Bluray-1080p-x265].eng.srt'
+ mainsrt='--track-name "0:English" --language "0:eng" Movie Name (2000) [Bluray-1080p-x265].eng.srt'
+ test -f 'Movie Name (2000) [Bluray-1080p-x265].eng.forced.srt'
+ forcedsrt='--track-name "0:English (Forced)" --language "0:eng" --forced-track "0:yes" --default-track "0:yes" Movie Name (2000) [Bluray-1080p-x265].eng.forced.srt'
+ test -f 'Movie Name (2000) [Bluray-1080p-x265].eng.sdh.srt'
+ mkvmerge -o '/home/username/Movie Name (2000) [Bluray-1080p-x265].mkv' 'Movie Name (2000) [Bluray-1080p-x265].mp4' '--track-name "0:English" --language "0:eng" Movie Name (2000) [Bluray-1080p-x265].eng.srt' '--track-name "0:English (Forced)" --language "0:eng" --forced-track "0:yes" --default-track "0:yes" Movie Name (2000) [Bluray-1080p-x265].eng.forced.srt' ''
mkvmerge v65.0.0 ('Too Much') 64-bit
Error: The file '--track-name "0:English" --language "0:eng" Movie Name (2000) [Bluray-1080p-x265].eng.srt' could not be opened for reading: open file error.
From looking at the output its adding a ' on the variables containing the subnoscript stuff which makes the command invalid. One example is before --track-name
The purpose of the "if test" lines is to test if the file exists - as not all files will have all subnoscript types and I wanted to make one noscript that works for all by having the noscript check if the file exists.
System info:
Ubuntu 22.04 Server
GNU bash, version 5.1.16(1)-release (x86\_64-pc-linux-gnu)
https://redd.it/zlkdo0
@r_bash
I'm making a noscript to convert mp4 to mkv while embedding subnoscripts but it doesn't work. If I am to put echo before mkverge on the last line and copy/paste the output into the terminal, it runs fine.
Here is a copy of the noscript:
#!/bin/bash
subfile=$(sed 's/mp4/eng.srt/' <<< "$1")
sdhsubfile=$(sed 's/mp4/eng.sdh.srt/' <<< "$1")
forcedsubfile=$(sed 's/mp4/eng.forced.srt/' <<< "$1")
outfile=$(sed 's/mp4/mkv/' <<< "$1")
if test -f "$subfile"; then
mainsrt='--track-name "0:English" --language "0:eng" '"$subfile"
fi
if test -f "$forcedsubfile"; then
forcedsrt='--track-name "0:English (Forced)" --language "0:eng" --forced-track "0:yes" --default-track "0:yes" '"$forcedsubfile"
fi
if test -f "$sdhsubfile"; then
sdhsrt='--track-name "0:English" --language "0:eng" "$subfile" --track-name "0:English (SDH)" --language "0:eng" '"$sdhsubfile"
fi
mkvmerge -o "$2/$outfile" "$1" "$mainsrt" "$forcedsrt" "$sdhsrt"
I added -x to the command so I could see the output and saw the following:
$ for i in *.mp4; do bash -x /noscripts/mp4_srt_to_mkv.sh "$i" "/home/username"; done
++ sed s/mp4/eng.srt/
+ subfile='Movie Name (2000) [Bluray-1080p-x265].eng.srt'
++ sed s/mp4/eng.sdh.srt/
+ sdhsubfile='Movie Name (2000) [Bluray-1080p-x265].eng.sdh.srt'
++ sed s/mp4/eng.forced.srt/
+ forcedsubfile='Movie Name (2000) [Bluray-1080p-x265].eng.forced.srt'
++ sed s/mp4/mkv/
+ outfile='Movie Name (2000) [Bluray-1080p-x265].mkv'
+ test -f 'Movie Name (2000) [Bluray-1080p-x265].eng.srt'
+ mainsrt='--track-name "0:English" --language "0:eng" Movie Name (2000) [Bluray-1080p-x265].eng.srt'
+ test -f 'Movie Name (2000) [Bluray-1080p-x265].eng.forced.srt'
+ forcedsrt='--track-name "0:English (Forced)" --language "0:eng" --forced-track "0:yes" --default-track "0:yes" Movie Name (2000) [Bluray-1080p-x265].eng.forced.srt'
+ test -f 'Movie Name (2000) [Bluray-1080p-x265].eng.sdh.srt'
+ mkvmerge -o '/home/username/Movie Name (2000) [Bluray-1080p-x265].mkv' 'Movie Name (2000) [Bluray-1080p-x265].mp4' '--track-name "0:English" --language "0:eng" Movie Name (2000) [Bluray-1080p-x265].eng.srt' '--track-name "0:English (Forced)" --language "0:eng" --forced-track "0:yes" --default-track "0:yes" Movie Name (2000) [Bluray-1080p-x265].eng.forced.srt' ''
mkvmerge v65.0.0 ('Too Much') 64-bit
Error: The file '--track-name "0:English" --language "0:eng" Movie Name (2000) [Bluray-1080p-x265].eng.srt' could not be opened for reading: open file error.
From looking at the output its adding a ' on the variables containing the subnoscript stuff which makes the command invalid. One example is before --track-name
The purpose of the "if test" lines is to test if the file exists - as not all files will have all subnoscript types and I wanted to make one noscript that works for all by having the noscript check if the file exists.
System info:
Ubuntu 22.04 Server
GNU bash, version 5.1.16(1)-release (x86\_64-pc-linux-gnu)
https://redd.it/zlkdo0
@r_bash
reddit
Bash adding extra single quotes when running noscript
I'm making a noscript to convert mp4 to mkv while embedding subnoscripts but it doesn't work. If I am to put echo before mkverge on the last line and...
BASH shell programming practice problems?
Does anyone know any recourses with some? Ideally just using common commands.
https://redd.it/zlldpo
@r_bash
Does anyone know any recourses with some? Ideally just using common commands.
https://redd.it/zlldpo
@r_bash
reddit
BASH shell programming practice problems?
Does anyone know any recourses with some? Ideally just using common commands.
Help me to convert this code to bash noscript
import sys
​
def main():
print(sys.argv)
print(len(sys.argv))
if len(sys.argv) != 2:
print("Usage: python3", sys.argv[0\], "<string>")
sys.exit(1)
else:
string = sys.argv[1\]
for i in string:
if i.isalpha():
print(i, ":", ord(i) - 96)
else:
print(i, ":", "-")
​
if __name__ == "__main__":
main()
https://redd.it/zll5b9
@r_bash
import sys
​
def main():
print(sys.argv)
print(len(sys.argv))
if len(sys.argv) != 2:
print("Usage: python3", sys.argv[0\], "<string>")
sys.exit(1)
else:
string = sys.argv[1\]
for i in string:
if i.isalpha():
print(i, ":", ord(i) - 96)
else:
print(i, ":", "-")
​
if __name__ == "__main__":
main()
https://redd.it/zll5b9
@r_bash
reddit
Help me to convert this code to bash noscript
import sys def main(): print(sys.argv) print(len(sys.argv)) if len(sys.argv) != 2: print("Usage: python3", sys.argv\[0\],...
question from a newbie. what's the best way to translate reply inputs?
Sorry about formatting, on mobile and its nearly 3 a.m. Right now I'm doing a project making a calculator in bash and I have everything done but one task. I need to translate the input from the operation select menu so it's always lower case. I feel so stupid but I can't figure it out and it's been hours.
This is my first interaction with bash noscripting and I gotten If then down but I'm struggling with loops.
Thank you, if you need my noscript I'll post in a few hours once I get some sleep.
https://redd.it/zll2qu
@r_bash
Sorry about formatting, on mobile and its nearly 3 a.m. Right now I'm doing a project making a calculator in bash and I have everything done but one task. I need to translate the input from the operation select menu so it's always lower case. I feel so stupid but I can't figure it out and it's been hours.
This is my first interaction with bash noscripting and I gotten If then down but I'm struggling with loops.
Thank you, if you need my noscript I'll post in a few hours once I get some sleep.
https://redd.it/zll2qu
@r_bash
reddit
question from a newbie. what's the best way to translate reply inputs?
Sorry about formatting, on mobile and its nearly 3 a.m. Right now I'm doing a project making a calculator in bash and I have everything done but...
How can I make an input function?
I was wondering if it's possible to make a simple function like this, where you can input a string while calling the function
stringLenghtCalculator($inputString){
"$(($(echo $inputString | wc -m)-1))"
}
https://redd.it/zlod9f
@r_bash
I was wondering if it's possible to make a simple function like this, where you can input a string while calling the function
stringLenghtCalculator(hello) and the function calculates the length of the input stringLenghtCalculator($inputString){
"$(($(echo $inputString | wc -m)-1))"
}
https://redd.it/zlod9f
@r_bash
reddit
How can I make an input function?
I was wondering if it's possible to make a simple function like this, where you can input a string while calling the function...
getent passwd {$min..$max} not working, {1000..60000} does
Hi! I'm trying to use getent passwd {$min..$max} in a noscript.
If I echo $min or echo $max before the getent command, it's 1000 and 60000 respectively.
getent passwd {1000..60000} gives me all info I need. Why doesn't variables work?
https://redd.it/zlo2wp
@r_bash
Hi! I'm trying to use getent passwd {$min..$max} in a noscript.
If I echo $min or echo $max before the getent command, it's 1000 and 60000 respectively.
getent passwd {1000..60000} gives me all info I need. Why doesn't variables work?
https://redd.it/zlo2wp
@r_bash
reddit
getent passwd {$min..$max} not working, {1000..60000} does
Hi! I'm trying to use getent passwd {$min..$max} in a noscript. If I echo $min or echo $max before the getent command, it's 1000 and 60000...
cp -rv command without verbosing only the dir name?
Is it possible to print only the dir names (and probably the subdirs) only when using cp with -v?
If the answer is awk, I'd kindly ask the exact solution.
https://redd.it/zlq7vp
@r_bash
Is it possible to print only the dir names (and probably the subdirs) only when using cp with -v?
If the answer is awk, I'd kindly ask the exact solution.
https://redd.it/zlq7vp
@r_bash
reddit
cp -rv command without verbosing only the dir name?
Is it possible to print only the dir names (and probably the subdirs) only when using cp with -v? If the answer is awk, I'd kindly ask the...
Need help with flag names
I have homework where I have to make a noscript that counts words, characters, lines, paragraphs and so on withot using things like wc. I have this done. The thing is, my teacher insists that when running the noscript in terminal, it has to be called like this:
./noscript.sh -file test.txt -number 10
I have all this done and it works, except I have no idea how to make it so that the flag names can be strings and not single characters, without using double dashes --.
Right now I have it like this:
./noscript.sh -f test.txt -n 10
And it all works, but how can I change my getopts (or is there a different way?), so that the flag names can be long?
Also, here is a snippet of my getopts part:
while getopts ":f:n:" opt; do
case $opt in
f) file=$OPTARG
​
Ive also tried doing it like ":file:number:" but it doesnt seem to work
https://redd.it/zltbom
@r_bash
I have homework where I have to make a noscript that counts words, characters, lines, paragraphs and so on withot using things like wc. I have this done. The thing is, my teacher insists that when running the noscript in terminal, it has to be called like this:
./noscript.sh -file test.txt -number 10
I have all this done and it works, except I have no idea how to make it so that the flag names can be strings and not single characters, without using double dashes --.
Right now I have it like this:
./noscript.sh -f test.txt -n 10
And it all works, but how can I change my getopts (or is there a different way?), so that the flag names can be long?
Also, here is a snippet of my getopts part:
while getopts ":f:n:" opt; do
case $opt in
f) file=$OPTARG
​
Ive also tried doing it like ":file:number:" but it doesnt seem to work
https://redd.it/zltbom
@r_bash
reddit
Need help with flag names
I have homework where I have to make a noscript that counts words, characters, lines, paragraphs and so on withot using things like wc. I have this...