"MovementData":
{
"timeToStrafeJog": 0.1,
"rotationSpeedJog": 0.3,
"timeToSprint": 0.45,
"timeToStrafeSprint": 0.3,
"rotationSpeedSprint": 0.15,
"allowStaminaAffectInertia": true
},
"DrowningData":
{
"staminaDepletionSpeed": 10.0,
"healthDepletionSpeed": 10.0,
"shockDepletionSpeed": 10.0
}
},
"WorldsData":
{
"lightingConfig": 1,
"objectSpawnersArr": ,
"environmentMinTemps": -3.0, -2.0, 0.0, 4.0, 9.0, 14.0, 18.0, 17.0, 12.0, 7.0, 4.0, 0.0,
"environmentMaxTemps": 3.0, 5.0, 7.0, 14.0, 19.0, 24.0, 26.0, 25.0, 21.0, 16.0, 10.0, 5.0,
"wetnessWeightModifiers": 1.0, 1.0, 1.33, 1.66, 2.0
},
"BaseBuildingData":
{
"HologramData":
{
"disableIsCollidingBBoxCheck": true,
"disableIsCollidingPlayerCheck": true,
"disableIsClippingRoofCheck": true,
"disableIsBaseViableCheck": true,
"disableIsCollidingGPlotCheck": true,
"disableIsCollidingAngleCheck": true,
"disableIsPlacementPermittedCheck": true,
"disableHeightPlacementCheck": true,
"disableIsUnderwaterCheck": true,
"disableIsInTerrainCheck": true,
"disallowedTypesInUnderground": "FenceKit","TerritoryFlagKit","WatchtowerKit"
},
"ConstructionData":
{
"disablePerformRoofCheck": true,
"disableIsCollidingCheck": true,
"disableDistanceCheck": true
}
},
"UIData":
{
"use3DMap": false,
"HitIndicationData":
{
"hitDirectionOverrideEnabled": false,
"hitDirectionBehaviour": 1,
"hitDirectionStyle": 0,
"hitDirectionIndicatorColorStr": "0xffbb0a1e",
"hitDirectionMaxDuration": 2.0,
"hitDirectionBreakPointRelative": 0.2,
"hitDirectionScatter": 10.0,
"hitIndicationPostProcessEnabled": true
}
},
"MapData":
{
"ignoreMapOwnership": true,
"ignoreNavItemsOwnership": true,
"displayPlayerPosition": true,
"displayNavInfo": true
}
}
If I run
jq -c --slurpfile f2 cfggameplaychanges.json '. + $f2[0]' cfggameplaysource.json
I get
{
"version": 122,
"GeneralData": {
"disableBaseDamage": false,
"disableContainerDamage": false,
"disableRespawnDialog": false,
"disableRespawnInUnconsciousness": false
},
"PlayerData": {
"disablePersonalLight": false,
"StaminaData": {
"sprintStaminaModifierErc": 1,
"sprintStaminaModifierCro": 1,
"staminaWeightLimitThreshold": 6000,
"staminaMax": 100,
"staminaKgToStaminaPercentPenalty": 1.75,
"staminaMinCap": 5,
"sprintSwimmingStaminaModifier": 1,
"sprintLadderStaminaModifier": 1,
"meleeStaminaModifier": 1,
"obstacleTraversalStaminaModifier": 1,
"holdBreathStaminaModifier": 1
},
"ShockHandlingData": {
"shockRefillSpeedConscious": 5,
"shockRefillSpeedUnconscious": 1,
"allowRefillSpeedModifier": true
},
"MovementData": {
"timeToStrafeJog": 0.1,
"rotationSpeedJog": 0.3,
"timeToSprint": 0.45,
"timeToStrafeSprint": 0.3,
"rotationSpeedSprint": 0.15,
"allowStaminaAffectInertia": true
},
"DrowningData": {
"staminaDepletionSpeed": 10,
"healthDepletionSpeed": 10,
"shockDepletionSpeed": 10
}
},
"WorldsData": {
"lightingConfig": 1,
"objectSpawnersArr": ,
"environmentMinTemps":
-3,
-2,
0,
4,
9,
14,
18,
17,
12,
7,
4,
0
,
"environmentMaxTemps":
3,
5,
7,
14,
19,
24,
26,
25,
21,
16,
10,
5
,
{
"timeToStrafeJog": 0.1,
"rotationSpeedJog": 0.3,
"timeToSprint": 0.45,
"timeToStrafeSprint": 0.3,
"rotationSpeedSprint": 0.15,
"allowStaminaAffectInertia": true
},
"DrowningData":
{
"staminaDepletionSpeed": 10.0,
"healthDepletionSpeed": 10.0,
"shockDepletionSpeed": 10.0
}
},
"WorldsData":
{
"lightingConfig": 1,
"objectSpawnersArr": ,
"environmentMinTemps": -3.0, -2.0, 0.0, 4.0, 9.0, 14.0, 18.0, 17.0, 12.0, 7.0, 4.0, 0.0,
"environmentMaxTemps": 3.0, 5.0, 7.0, 14.0, 19.0, 24.0, 26.0, 25.0, 21.0, 16.0, 10.0, 5.0,
"wetnessWeightModifiers": 1.0, 1.0, 1.33, 1.66, 2.0
},
"BaseBuildingData":
{
"HologramData":
{
"disableIsCollidingBBoxCheck": true,
"disableIsCollidingPlayerCheck": true,
"disableIsClippingRoofCheck": true,
"disableIsBaseViableCheck": true,
"disableIsCollidingGPlotCheck": true,
"disableIsCollidingAngleCheck": true,
"disableIsPlacementPermittedCheck": true,
"disableHeightPlacementCheck": true,
"disableIsUnderwaterCheck": true,
"disableIsInTerrainCheck": true,
"disallowedTypesInUnderground": "FenceKit","TerritoryFlagKit","WatchtowerKit"
},
"ConstructionData":
{
"disablePerformRoofCheck": true,
"disableIsCollidingCheck": true,
"disableDistanceCheck": true
}
},
"UIData":
{
"use3DMap": false,
"HitIndicationData":
{
"hitDirectionOverrideEnabled": false,
"hitDirectionBehaviour": 1,
"hitDirectionStyle": 0,
"hitDirectionIndicatorColorStr": "0xffbb0a1e",
"hitDirectionMaxDuration": 2.0,
"hitDirectionBreakPointRelative": 0.2,
"hitDirectionScatter": 10.0,
"hitIndicationPostProcessEnabled": true
}
},
"MapData":
{
"ignoreMapOwnership": true,
"ignoreNavItemsOwnership": true,
"displayPlayerPosition": true,
"displayNavInfo": true
}
}
If I run
jq -c --slurpfile f2 cfggameplaychanges.json '. + $f2[0]' cfggameplaysource.json
I get
{
"version": 122,
"GeneralData": {
"disableBaseDamage": false,
"disableContainerDamage": false,
"disableRespawnDialog": false,
"disableRespawnInUnconsciousness": false
},
"PlayerData": {
"disablePersonalLight": false,
"StaminaData": {
"sprintStaminaModifierErc": 1,
"sprintStaminaModifierCro": 1,
"staminaWeightLimitThreshold": 6000,
"staminaMax": 100,
"staminaKgToStaminaPercentPenalty": 1.75,
"staminaMinCap": 5,
"sprintSwimmingStaminaModifier": 1,
"sprintLadderStaminaModifier": 1,
"meleeStaminaModifier": 1,
"obstacleTraversalStaminaModifier": 1,
"holdBreathStaminaModifier": 1
},
"ShockHandlingData": {
"shockRefillSpeedConscious": 5,
"shockRefillSpeedUnconscious": 1,
"allowRefillSpeedModifier": true
},
"MovementData": {
"timeToStrafeJog": 0.1,
"rotationSpeedJog": 0.3,
"timeToSprint": 0.45,
"timeToStrafeSprint": 0.3,
"rotationSpeedSprint": 0.15,
"allowStaminaAffectInertia": true
},
"DrowningData": {
"staminaDepletionSpeed": 10,
"healthDepletionSpeed": 10,
"shockDepletionSpeed": 10
}
},
"WorldsData": {
"lightingConfig": 1,
"objectSpawnersArr": ,
"environmentMinTemps":
-3,
-2,
0,
4,
9,
14,
18,
17,
12,
7,
4,
0
,
"environmentMaxTemps":
3,
5,
7,
14,
19,
24,
26,
25,
21,
16,
10,
5
,
"wetnessWeightModifiers":
1,
1,
1.33,
1.66,
2
},
"BaseBuildingData": {
"HologramData": {
"disableIsCollidingBBoxCheck": true,
"disableIsCollidingPlayerCheck": true,
"disableIsClippingRoofCheck": true,
"disableIsBaseViableCheck": true,
"disableIsCollidingGPlotCheck": true,
"disableIsCollidingAngleCheck": true,
"disableIsPlacementPermittedCheck": true,
"disableHeightPlacementCheck": true,
"disableIsUnderwaterCheck": true,
"disableIsInTerrainCheck": true,
"disallowedTypesInUnderground":
"FenceKit",
"TerritoryFlagKit",
"WatchtowerKit"
},
"ConstructionData": {
"disablePerformRoofCheck": true,
"disableIsCollidingCheck": true,
"disableDistanceCheck": true
}
},
"UIData": {
"use3DMap": false,
"HitIndicationData": {
"hitDirectionOverrideEnabled": false,
"hitDirectionBehaviour": 1,
"hitDirectionStyle": 0,
"hitDirectionIndicatorColorStr": "0xffbb0a1e",
"hitDirectionMaxDuration": 2,
"hitDirectionBreakPointRelative": 0.2,
"hitDirectionScatter": 10,
"hitIndicationPostProcessEnabled": true
}
},
"MapData": {
"ignoreMapOwnership": true,
"ignoreNavItemsOwnership": true,
"displayPlayerPosition": true,
"displayNavInfo": true
}
}
Which is sooooo close to what I need. How do I turn these
"wetnessWeightModifiers":
1,
1,
1.33,
1.66,
2
into this
"wetnessWeightModifiers": 1,1,1.33,1.66,2
and preferably keep the decimals from the original "1.0,1.0,1.33,1.66,2.0" thank you so much for your assistance in advance.
https://redd.it/17rpl3z
@r_bash
1,
1,
1.33,
1.66,
2
},
"BaseBuildingData": {
"HologramData": {
"disableIsCollidingBBoxCheck": true,
"disableIsCollidingPlayerCheck": true,
"disableIsClippingRoofCheck": true,
"disableIsBaseViableCheck": true,
"disableIsCollidingGPlotCheck": true,
"disableIsCollidingAngleCheck": true,
"disableIsPlacementPermittedCheck": true,
"disableHeightPlacementCheck": true,
"disableIsUnderwaterCheck": true,
"disableIsInTerrainCheck": true,
"disallowedTypesInUnderground":
"FenceKit",
"TerritoryFlagKit",
"WatchtowerKit"
},
"ConstructionData": {
"disablePerformRoofCheck": true,
"disableIsCollidingCheck": true,
"disableDistanceCheck": true
}
},
"UIData": {
"use3DMap": false,
"HitIndicationData": {
"hitDirectionOverrideEnabled": false,
"hitDirectionBehaviour": 1,
"hitDirectionStyle": 0,
"hitDirectionIndicatorColorStr": "0xffbb0a1e",
"hitDirectionMaxDuration": 2,
"hitDirectionBreakPointRelative": 0.2,
"hitDirectionScatter": 10,
"hitIndicationPostProcessEnabled": true
}
},
"MapData": {
"ignoreMapOwnership": true,
"ignoreNavItemsOwnership": true,
"displayPlayerPosition": true,
"displayNavInfo": true
}
}
Which is sooooo close to what I need. How do I turn these
"wetnessWeightModifiers":
1,
1,
1.33,
1.66,
2
into this
"wetnessWeightModifiers": 1,1,1.33,1.66,2
and preferably keep the decimals from the original "1.0,1.0,1.33,1.66,2.0" thank you so much for your assistance in advance.
https://redd.it/17rpl3z
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Issue making JSON string
So I need to make a pure JSON string using a variable, and I'm bashing (no pun intended) my head against the wall trying to get the result I want:
The desired result looks like this:
'{"app":"app-version.tar","db":"db-version.tar"}'
The variable I have would contain the version info (so like, $VERSION), and I CANNOT get a proper JSON out of something like
'{"app":"app-'$VERSION'.tar","db":"db-'$VERSION'.tar"}'
Anyone able to help?
Edit: I also need to echo the EXACT string being generated at some earlier point as well, for making sure everything is correct.
https://redd.it/17rpjsh
@r_bash
So I need to make a pure JSON string using a variable, and I'm bashing (no pun intended) my head against the wall trying to get the result I want:
The desired result looks like this:
'{"app":"app-version.tar","db":"db-version.tar"}'
The variable I have would contain the version info (so like, $VERSION), and I CANNOT get a proper JSON out of something like
'{"app":"app-'$VERSION'.tar","db":"db-'$VERSION'.tar"}'
Anyone able to help?
Edit: I also need to echo the EXACT string being generated at some earlier point as well, for making sure everything is correct.
https://redd.it/17rpjsh
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Back to being a little confused about quoting
Could some kind soul take look here and maybe improve it to be "good". In particular, why doesn't it work if I double quote the use of ${OPTS} ? I'm probably mixing up differnt bash styles as this was made from cut and paste of answers on SO for each bit.
​
>\#!/usr/bin/env bash
>
>\# Maintained in linux-config.org
>
>LOGFILE="${HOME}/rclone-bisync-$(date +"%Y_%m_%d_%I_%M_%p").log"
>
>OPTS="--log-file=${LOGFILE} --log-level INFO --checkers=16 --drive-pacer-min-sleep=10ms --resilient --links --ignore-listing-checksum --check-sync=false --tpslimit=10 --drive-chunk-size=256M --drive-use-trash=false --fast-list ${HOME}/cloud cloud:"
>
>if pgrep -x "rclone" > /dev/null
>
>then
>
>echo "rclone already running. Bye." >> "$LOGFILE"
>
>exit 0
>
>fi
>
>mv rclone-bisync*.log "$HOME/tmp" 2>/dev/null
>
>rclone bisync ${OPTS}
>
>retVal=$?
>
>if [ $retVal -ne 0 \]; then
>
>echo "Error (${retVal}) last bisync. Doing a resync." >> "$LOGFILE"
>
>rclone bisync --resync ${OPTS}
>
>else
>
>echo "rclone bisync finished without error." >> "$LOGFILE"
>
>fi
​
https://redd.it/17rzabs
@r_bash
Could some kind soul take look here and maybe improve it to be "good". In particular, why doesn't it work if I double quote the use of ${OPTS} ? I'm probably mixing up differnt bash styles as this was made from cut and paste of answers on SO for each bit.
​
>\#!/usr/bin/env bash
>
>\# Maintained in linux-config.org
>
>LOGFILE="${HOME}/rclone-bisync-$(date +"%Y_%m_%d_%I_%M_%p").log"
>
>OPTS="--log-file=${LOGFILE} --log-level INFO --checkers=16 --drive-pacer-min-sleep=10ms --resilient --links --ignore-listing-checksum --check-sync=false --tpslimit=10 --drive-chunk-size=256M --drive-use-trash=false --fast-list ${HOME}/cloud cloud:"
>
>if pgrep -x "rclone" > /dev/null
>
>then
>
>echo "rclone already running. Bye." >> "$LOGFILE"
>
>exit 0
>
>fi
>
>mv rclone-bisync*.log "$HOME/tmp" 2>/dev/null
>
>rclone bisync ${OPTS}
>
>retVal=$?
>
>if [ $retVal -ne 0 \]; then
>
>echo "Error (${retVal}) last bisync. Doing a resync." >> "$LOGFILE"
>
>rclone bisync --resync ${OPTS}
>
>else
>
>echo "rclone bisync finished without error." >> "$LOGFILE"
>
>fi
​
https://redd.it/17rzabs
@r_bash
Syntax error due to wrong parsing
Is there a way to fix the syntax in the *SEARCH\_STRING* to avoid the error ?
Script:
*SEARCH\_STRING="search sourcetype="datasource" "denied" earliest=-60m | rex field=\_raw* ***"from (?<from>.\*)"*** *|table from |stats count by from |sort -count"*
*curl -H "Authorization: Bearer $TOKEN" -X POST https://$SPLUNK\_HOST:8089/services/search/jobs -d search="$SEARCH\_STRING";*
​
Output:
*$ ./splunk\_search.bash*
*./splunk\_search.bash: line 9: syntax error near unexpected token \`('*
*./splunk\_search.bash: line 9: \`SEARCH\_STRING="search sourcetype="datasource" "denied" earliest=-60m | rex field=\_raw "from (?<from>.\*)" |table from |stats count by from |sort -count"'*
https://redd.it/17s0yjf
@r_bash
Is there a way to fix the syntax in the *SEARCH\_STRING* to avoid the error ?
Script:
*SEARCH\_STRING="search sourcetype="datasource" "denied" earliest=-60m | rex field=\_raw* ***"from (?<from>.\*)"*** *|table from |stats count by from |sort -count"*
*curl -H "Authorization: Bearer $TOKEN" -X POST https://$SPLUNK\_HOST:8089/services/search/jobs -d search="$SEARCH\_STRING";*
​
Output:
*$ ./splunk\_search.bash*
*./splunk\_search.bash: line 9: syntax error near unexpected token \`('*
*./splunk\_search.bash: line 9: \`SEARCH\_STRING="search sourcetype="datasource" "denied" earliest=-60m | rex field=\_raw "from (?<from>.\*)" |table from |stats count by from |sort -count"'*
https://redd.it/17s0yjf
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
remove "" char from filenames
Hi,
this might seem like a dumb question but I can't find a way to do this.
I have a folder with a bunch of files, some of them contain asterisks in their names (\). Is there a way to remove them ? (maybe with mv)
https://redd.it/17s2w0n
@r_bash
Hi,
this might seem like a dumb question but I can't find a way to do this.
I have a folder with a bunch of files, some of them contain asterisks in their names (\). Is there a way to remove them ? (maybe with mv)
https://redd.it/17s2w0n
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Is there a way to save executed keyboard shortcuts from the cli to a file or to stdout?
Sometimes I'd be exploring the different keybinding I have and I accidentally pressed a combination (like Alt + U or I'd change from emacs to vim or whatever) but I wouldn't know what I'd press because I'm just messing around or I pressed this keyboard shortcut by accident.
Is there a way to output to stdout or save to a file that, for example, says I pressed alt + u and give a short denoscription that mentions I changed the text to upper case or I pressed ctrl + y and that yanks the line.
I accidentally fat finger my keyboard shortcuts all the time and I can't figure out what I just pressed. It would help me debug my keyboard shortcut and learn what I actually pressed.
https://redd.it/17sagaf
@r_bash
Sometimes I'd be exploring the different keybinding I have and I accidentally pressed a combination (like Alt + U or I'd change from emacs to vim or whatever) but I wouldn't know what I'd press because I'm just messing around or I pressed this keyboard shortcut by accident.
Is there a way to output to stdout or save to a file that, for example, says I pressed alt + u and give a short denoscription that mentions I changed the text to upper case or I pressed ctrl + y and that yanks the line.
I accidentally fat finger my keyboard shortcuts all the time and I can't figure out what I just pressed. It would help me debug my keyboard shortcut and learn what I actually pressed.
https://redd.it/17sagaf
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
A few common shell functions (cat, mktemp, wc -c, and sleep) re-implemented in pure bash
I re-implemented a few common shell functions (that dont bash builtins with equivalent functionality) in pure bash. Anyone else do this? Anyone have any to add?
My use case for these tends to be to use them as "backups" when I want a code to be able to run on an embedded machine that has bash but everything else is not guaranteed. i.e.,
type -p FUNC >&/dev/null || {
FUNC() {
...
}
}
Here are the re-implemented functions. Each has a quick test along with it to ensure it is working. The functionality is not always an exact match to the original (not all flags are implemented...just the core functionality). But, for what is implemented it should (I think) be a drop-in replacement.
mktemp() {
local tmpFile
# generate tempfile name, and repeat until we get one that doesnt exist.
tmpFile=/tmp/.tmp.${RANDOM}
while [ -f "$tmpFile" ]; do
tmpFile=/tmp/.tmp.${RANDOM}
done
# touch tmpfile then echo its path
touch "${tmpFile}"
echo "${tmpFile}"
}
# test mktemp
file="$(mktemp)"
[ -f "${file}" ] && echo "tmpfile exists" >&2
echo
cat() {
if [ -t 0 ] && [ $# == 0 ]; then
# no input
return
elif [ $# == 0 ]; then
# only stdin
printf '%s\n' "$(</proc/self/fd/0)"
elif [ -t 0 ]; then
# only function inputs
source <(printf 'echo '; printf '"$(<"%s")" ' "$@"; printf '\n')
else
# both stdin and function inputs. fork printing stdin.
{ printf '%s\n' "$(</proc/self/fd/0)" >&9 & } 9>&1
source <(printf 'echo '; printf '"$(<"%s")" ' "$@"; printf '\n')
fi
}
# test cat
printf '%s\n' hi bye > "${file}"
printf '%s\n' hola adios | cat "${file}"
echo
wc() {
# only char/byte count (-c flag) implemented
# check for no input case
[ -t 0 ] && [ $# == 0 ] && return
# make tmpfile
local tmpFile fd waitFlag
tmpFile="$(mktemp)"
(
waitFlag=false
# add stdin, if anything is there
[ -t 0 ] || {
if [ $# == 0 ]; then
cat >&${fd}
else
# if we also are adding files then fork adding stdin
waitFlag=true
{ cat <&9 >&${fd} & } 9<&0
fi
}
# add function inputs that are files
for nn in "$@"; do
[ -f "$nn" ] && echo "$(<"${nn}")" >&${fd}
done
# wait for forked cat of stdin (if needed)
${waitFlag} && wait
# get the current position of fd
read </proc/self/fdinfo/${fd}
echo "${REPLY##$'\t'}"
) {fd}>>"${tmpFile}"
# remove tmpfile
[[ -f "${tmpFile}" ]] && \rm -f "${tmpFile}"
}
# test wc
printf '%s\n' hola adios | wc "${file}"
echo
sleep() {
local dur
# get sleep duration. default to 1 if missing.invalid
[[ "$1" =~ ^[0-9]\.?0-9+$ ]] && dur="$1" || dur=1
(
# read from empty anonymous pipe with timeout
read -u ${fd} -t "$dur"
) {fd}<><(:)
}
# test sleep
echo "hi - ${EPOCHREALTIME}"
sleep 2
echo "bye - ${EPOCHREALTIME}"
echo
https://redd.it/17scg3v
@r_bash
I re-implemented a few common shell functions (that dont bash builtins with equivalent functionality) in pure bash. Anyone else do this? Anyone have any to add?
My use case for these tends to be to use them as "backups" when I want a code to be able to run on an embedded machine that has bash but everything else is not guaranteed. i.e.,
type -p FUNC >&/dev/null || {
FUNC() {
...
}
}
Here are the re-implemented functions. Each has a quick test along with it to ensure it is working. The functionality is not always an exact match to the original (not all flags are implemented...just the core functionality). But, for what is implemented it should (I think) be a drop-in replacement.
mktemp() {
local tmpFile
# generate tempfile name, and repeat until we get one that doesnt exist.
tmpFile=/tmp/.tmp.${RANDOM}
while [ -f "$tmpFile" ]; do
tmpFile=/tmp/.tmp.${RANDOM}
done
# touch tmpfile then echo its path
touch "${tmpFile}"
echo "${tmpFile}"
}
# test mktemp
file="$(mktemp)"
[ -f "${file}" ] && echo "tmpfile exists" >&2
echo
cat() {
if [ -t 0 ] && [ $# == 0 ]; then
# no input
return
elif [ $# == 0 ]; then
# only stdin
printf '%s\n' "$(</proc/self/fd/0)"
elif [ -t 0 ]; then
# only function inputs
source <(printf 'echo '; printf '"$(<"%s")" ' "$@"; printf '\n')
else
# both stdin and function inputs. fork printing stdin.
{ printf '%s\n' "$(</proc/self/fd/0)" >&9 & } 9>&1
source <(printf 'echo '; printf '"$(<"%s")" ' "$@"; printf '\n')
fi
}
# test cat
printf '%s\n' hi bye > "${file}"
printf '%s\n' hola adios | cat "${file}"
echo
wc() {
# only char/byte count (-c flag) implemented
# check for no input case
[ -t 0 ] && [ $# == 0 ] && return
# make tmpfile
local tmpFile fd waitFlag
tmpFile="$(mktemp)"
(
waitFlag=false
# add stdin, if anything is there
[ -t 0 ] || {
if [ $# == 0 ]; then
cat >&${fd}
else
# if we also are adding files then fork adding stdin
waitFlag=true
{ cat <&9 >&${fd} & } 9<&0
fi
}
# add function inputs that are files
for nn in "$@"; do
[ -f "$nn" ] && echo "$(<"${nn}")" >&${fd}
done
# wait for forked cat of stdin (if needed)
${waitFlag} && wait
# get the current position of fd
read </proc/self/fdinfo/${fd}
echo "${REPLY##$'\t'}"
) {fd}>>"${tmpFile}"
# remove tmpfile
[[ -f "${tmpFile}" ]] && \rm -f "${tmpFile}"
}
# test wc
printf '%s\n' hola adios | wc "${file}"
echo
sleep() {
local dur
# get sleep duration. default to 1 if missing.invalid
[[ "$1" =~ ^[0-9]\.?0-9+$ ]] && dur="$1" || dur=1
(
# read from empty anonymous pipe with timeout
read -u ${fd} -t "$dur"
) {fd}<><(:)
}
# test sleep
echo "hi - ${EPOCHREALTIME}"
sleep 2
echo "bye - ${EPOCHREALTIME}"
echo
https://redd.it/17scg3v
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Deferring process substitution
So here is a very basic example of process substitution:
This will result in the number 4 being printed at the onset of a new bash session. However, in the following case, the number is not printed:
For anyone unfamiliar, this command connects to an existing docker container named 'ubuntu_container' and executes the bash command. Although this successfully results in starting a bash session within the container, the number 4 is not printed.
My best guess is that the process substitution executes immediately, resulting in a filepath that is valid outside the container, but invalid within the container. Thus it cannot be used when starting a bash session inside the container.
Does anyone know of a way to get this second example to work? My topic noscript refers to 'deferring' the process substitution because if I could defer it until after entering the docker container, I believe everything would work.
Thank you.
​
(EDIT: For anyone curious, what I'm actually trying to do is to launch bash inside a docker container with a custom prompt by setting the PS1 environmental variable.)
https://redd.it/17smxs8
@r_bash
So here is a very basic example of process substitution:
bash --init-file <(echo "echo 4")This will result in the number 4 being printed at the onset of a new bash session. However, in the following case, the number is not printed:
docker exec -it ubuntu_container bash --init-file <(echo "echo 4")For anyone unfamiliar, this command connects to an existing docker container named 'ubuntu_container' and executes the bash command. Although this successfully results in starting a bash session within the container, the number 4 is not printed.
My best guess is that the process substitution executes immediately, resulting in a filepath that is valid outside the container, but invalid within the container. Thus it cannot be used when starting a bash session inside the container.
Does anyone know of a way to get this second example to work? My topic noscript refers to 'deferring' the process substitution because if I could defer it until after entering the docker container, I believe everything would work.
Thank you.
​
(EDIT: For anyone curious, what I'm actually trying to do is to launch bash inside a docker container with a custom prompt by setting the PS1 environmental variable.)
https://redd.it/17smxs8
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Help with basic folder perms (beginner)
Hey !
Im kinda new to bash, and im having a pretty basic problem here.
I have a minecraft server that restart, calling start.sh on restart.
When my ssh user do a bash start.sh, it works fine.
However, when the server execute it itself, the first instructions dont execute.
I'm pretty certain its a permission problem, but i cant figure why, because it should be accessible by everyone (first pic), and somehow, when the server restarts, the perms change (second pic)
Here is the bash i execute.
rm -r ./world
sleep 3
unzip -o lobby.zip -d world
sleep 3
java -Xmx3G -jar paper.jar #This get executed anyway
(sorry if there is code blocs, i dont know how)
​
When user execute bash noscript
After restart
https://redd.it/17spxh4
@r_bash
Hey !
Im kinda new to bash, and im having a pretty basic problem here.
I have a minecraft server that restart, calling start.sh on restart.
When my ssh user do a bash start.sh, it works fine.
However, when the server execute it itself, the first instructions dont execute.
I'm pretty certain its a permission problem, but i cant figure why, because it should be accessible by everyone (first pic), and somehow, when the server restarts, the perms change (second pic)
Here is the bash i execute.
rm -r ./world
sleep 3
unzip -o lobby.zip -d world
sleep 3
java -Xmx3G -jar paper.jar #This get executed anyway
(sorry if there is code blocs, i dont know how)
​
When user execute bash noscript
After restart
https://redd.it/17spxh4
@r_bash
PS1
I have recently started to use oh my bash and now I want to change the color of my PS1 (custome prompt) how should I do it.
I do not seem to have anything regarding PS1 in my .bashrc .
Please help
https://redd.it/17sqrm5
@r_bash
I have recently started to use oh my bash and now I want to change the color of my PS1 (custome prompt) how should I do it.
I do not seem to have anything regarding PS1 in my .bashrc .
Please help
https://redd.it/17sqrm5
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Glassfish/payara domain restart project, any improvements you would say?
function domain_action() {
case $1 in
1)
echo "instruction received to start domain $2"
/home/techyman/glassfish4/bin/asadmin start-domain "$2"
;;
2)
echo "instruction received to stop domain $2"
/home/techyman/glassfish4/bin/asadmin stop-domain "$2"
;;
3)
echo "instruction received to restart domain $2"
/home/techyman/glassfish4/bin/asadmin stop-domain "$2" && /home/techyman/glassfish4/bin/asadmin start-domain "$2"
;;
esac
}
echo "What action do you want to perform? (1 for Start, 2 for Stop, 3 for Restart)"
read actionToPerform
echo "On which domains do you want to perform these actions?"
read -a arrayOfDomains
# https://stackoverflow.com/a/56146307/21719190
for domain in "${arrayOfDomains[@]}"; do
domain_action "$actionToPerform" "$domain"
#echo "$domain"
#https://ryanstutorials.net/bash-noscripting-tutorial/bash-if-statements.php
#if [ "$actionToPerform" = "1" ]; then
# echo "Starting $domain"
# domain_action "$actionToPerform" "$domain"
#elif [ "$actionToPerform" = "2" ]; then
# echo "Stopping $domain"
# domain_action "$actionToPerform" "$domain"
#else
# [ "$actionToPerform" = "3" ]
# echo "Restarting $domain"
# domain_action "$actionToPerform" "$domain"
#fi
done
https://redd.it/17tinew
@r_bash
function domain_action() {
case $1 in
1)
echo "instruction received to start domain $2"
/home/techyman/glassfish4/bin/asadmin start-domain "$2"
;;
2)
echo "instruction received to stop domain $2"
/home/techyman/glassfish4/bin/asadmin stop-domain "$2"
;;
3)
echo "instruction received to restart domain $2"
/home/techyman/glassfish4/bin/asadmin stop-domain "$2" && /home/techyman/glassfish4/bin/asadmin start-domain "$2"
;;
esac
}
echo "What action do you want to perform? (1 for Start, 2 for Stop, 3 for Restart)"
read actionToPerform
echo "On which domains do you want to perform these actions?"
read -a arrayOfDomains
# https://stackoverflow.com/a/56146307/21719190
for domain in "${arrayOfDomains[@]}"; do
domain_action "$actionToPerform" "$domain"
#echo "$domain"
#https://ryanstutorials.net/bash-noscripting-tutorial/bash-if-statements.php
#if [ "$actionToPerform" = "1" ]; then
# echo "Starting $domain"
# domain_action "$actionToPerform" "$domain"
#elif [ "$actionToPerform" = "2" ]; then
# echo "Stopping $domain"
# domain_action "$actionToPerform" "$domain"
#else
# [ "$actionToPerform" = "3" ]
# echo "Restarting $domain"
# domain_action "$actionToPerform" "$domain"
#fi
done
https://redd.it/17tinew
@r_bash
Stack Overflow
Shell noscript read multiple inputs from user
How to read any number of inputs from user at once and store it into an array.
For example this will read only a single input at a time
read -p "Please enter username: " username
echo "Dear $
For example this will read only a single input at a time
read -p "Please enter username: " username
echo "Dear $
man tool | cat | grep "string"
Out of curiosity, why doesn't grep work after cat? Isn't the stdout just a "textfile"? Ok, now thinking about this, I actually didn't try to run it with root privileges. But would it matter though?
https://redd.it/17tntom
@r_bash
Out of curiosity, why doesn't grep work after cat? Isn't the stdout just a "textfile"? Ok, now thinking about this, I actually didn't try to run it with root privileges. But would it matter though?
https://redd.it/17tntom
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
How to remove single new lines from the end of a line in a text file, but ignore double new lines
I have been tearing my hair out trying to process some text files that have too many new lines.
I have a text file that look s something like this:
The quick brown fox jumps Over the
lazy dog. The quick brown fox.
The quick brown fox
jumps over the lazy dog.
I want to remove the single newlines but ignore the doubles.
In a text editor I can find and place using regex like this:
Find: \n(?!\n) Replace with: <space>
But I have a bunch of files, so I’m looking for a way I can create a noscript to do it.
I’ve tried see/gsed, but it is ignoring my regular expressions, even with the -E option. Even a simple search for a newline fails:
sed -i -E 's/\n/ /g' test.txt
Does anyone have a solution?
Many thanks.
https://redd.it/17twwyv
@r_bash
I have been tearing my hair out trying to process some text files that have too many new lines.
I have a text file that look s something like this:
The quick brown fox jumps Over the
lazy dog. The quick brown fox.
The quick brown fox
jumps over the lazy dog.
I want to remove the single newlines but ignore the doubles.
In a text editor I can find and place using regex like this:
Find: \n(?!\n) Replace with: <space>
But I have a bunch of files, so I’m looking for a way I can create a noscript to do it.
I’ve tried see/gsed, but it is ignoring my regular expressions, even with the -E option. Even a simple search for a newline fails:
sed -i -E 's/\n/ /g' test.txt
Does anyone have a solution?
Many thanks.
https://redd.it/17twwyv
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
weird behaviors
curl -s https://english-e-reader.net/level/pre-intermediate | grep "/book/.*>" | sed 's/<a.*="//' | sed 's/">//' |sed 's|\^|https://english-e-reader.net|' | xargs -n 1 curl -s | grep -E "\^words: " >> out
I cannot write anything to the out file, but without redirecting to the file, everything went right.
https://redd.it/17v73mz
@r_bash
curl -s https://english-e-reader.net/level/pre-intermediate | grep "/book/.*>" | sed 's/<a.*="//' | sed 's/">//' |sed 's|\^|https://english-e-reader.net|' | xargs -n 1 curl -s | grep -E "\^words: " >> out
I cannot write anything to the out file, but without redirecting to the file, everything went right.
https://redd.it/17v73mz
@r_bash
English e-reader
graded readers ebooks - best choice to learn English. Download or read online for free!
Is the -f in rm -rf a bit useless?
There's a lot of jokes about
But if it does exist and we run
https://redd.it/17vgh0i
@r_bash
There's a lot of jokes about
rm -rf but if the directory doesn't exist and you run rm -r, it would throw an error, no big deal.But if it does exist and we run
rm -r then it deletes the directory recursively. As a standalone command rm -rfdoesn't seem that much different from rm -r. So maybe I don't understand the joke about rm -rf but rm -r should be good enough? I mean we obviously can't delete something that doesn't exist and -f just suppresses that error message. The importance of -f seems to be overstated?https://redd.it/17vgh0i
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Bash Script YouTube Downloader
https://medium.com/@mwikyo/download-youtube-videos-through-the-terminal-using-a-bash-noscript-205b21161339
https://redd.it/17vfvsa
@r_bash
https://medium.com/@mwikyo/download-youtube-videos-through-the-terminal-using-a-bash-noscript-205b21161339
https://redd.it/17vfvsa
@r_bash
Medium
Download YouTube videos through the terminal using a bash noscript.
If you have always wanted to download youtube videos with your own piece of software, no ads-filled and limiting online tools, even those…
"if grep" is a bomb that we ignore
https://blog.ngs-lang.org/2023/11/07/if-grep-the-bomb/
https://redd.it/17vncx8
@r_bash
https://blog.ngs-lang.org/2023/11/07/if-grep-the-bomb/
https://redd.it/17vncx8
@r_bash
Next Generation Shell
“if grep”, the bomb
Take 2 This is version two of the post, based on the feedback in this Reddit discussion. Some things need clarification. That includes the noscript which should be something like Why NGS has more ergo…
Monitor text file and run command on change?
I'm writing a now-playing Spotify noscript with semi cool formating...
When I ask playerctl for metadata I get a mpris:length (with a number) line, among the others.
I am currently giving that (number) to a Var and checking it every second and then re-running the noscript on change.
I read about a tool that can watch a file and run a command on change of file. I just can't remember what it was. I was thinking I could put the length into a txt file and watch it.
Is it worth using this other tool (that some great haxor will name) to watch the file?
I'm trying to lower system resource use of course.
https://redd.it/17vu88w
@r_bash
I'm writing a now-playing Spotify noscript with semi cool formating...
When I ask playerctl for metadata I get a mpris:length (with a number) line, among the others.
I am currently giving that (number) to a Var and checking it every second and then re-running the noscript on change.
I read about a tool that can watch a file and run a command on change of file. I just can't remember what it was. I was thinking I could put the length into a txt file and watch it.
Is it worth using this other tool (that some great haxor will name) to watch the file?
I'm trying to lower system resource use of course.
https://redd.it/17vu88w
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
jazz : through a marriage of jq and fzf, fuzzy select json input in terminal [homemade gist]
https://gist.github.com/grdscrc/2d0b0549f48950e12d0386bb0fbd8b4f
https://redd.it/17w065j
@r_bash
https://gist.github.com/grdscrc/2d0b0549f48950e12d0386bb0fbd8b4f
https://redd.it/17w065j
@r_bash
Gist
jazz : list paths from a json input, fuzzy search a node, get its content ; useful with large payloads
jazz : list paths from a json input, fuzzy search a node, get its content ; useful with large payloads - jazz.sh
Trying to set a noscript that will move files to different directories based off size
I can’t figure out how to set a shell noscript that when I run it will allow me to move a files above or below a certain size into two different directories and was wondering if anyone knew how.
https://redd.it/17w47wx
@r_bash
I can’t figure out how to set a shell noscript that when I run it will allow me to move a files above or below a certain size into two different directories and was wondering if anyone knew how.
https://redd.it/17w47wx
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community