r_bash – Telegram
variable value to create new variable

I'm new to bash and wondering whether it is possible to have the value stored in a variable to create another variable?

myvar=helloworld1

The value of myvar will be a dynamic, meaning that it will output helloworld1, or helloworld2 or helloworld3.

How can i achieve making the value of myvar as the name of a new variable?

https://redd.it/y9qo1l
@r_bash
increase the size of command history

I think this is a simple configuration using two environment variables. But, for some reason my system is honoring these variables. Does anyone have an idea why could this be?

$ echo $HISTSIZE 
10000
$ echo $HISTFILESIZE
20000
$ wc $HISTFILE
503 1549 14025 /home/someuser/.bash_history


thank you

https://redd.it/ya0hkh
@r_bash
Good Beginner Manual Recommendations?

I’m fairly new to bash noscripting and i’m currently working on a program for my bioinformatics class. I feel like my notes aren’t sufficient though for efficacy and I was wondering if anyone recommends an updated beginner manual that they liked.

Thanks :)

https://redd.it/yaekmr
@r_bash
Syntax error near unexpected token 'done'

Im sure its something embarrassingly simple, but i am new to this and ive been trying to get this to run for like an hour now. Can anyone help me understand why its not expecting done? This is on a chroot installation of fedora 35 on android 12 if it matters.

#!/usr/bin/bash
port=null
while :
do
wget -O ftp://192.168.1.3/port.txt
if $port == $(tail --lines 1 /home/port.txt | tr -d \\r);
then
echo "skipping service update and avahi restart"
cat >/dev/null << SKIPRESTART
else
echo "updating port, restarting avahi"
$port=$(tail --lines 1 /home/port.txt | tr -d \\r)
cat > /etc/avahi/services/oculus.service <<EOF
<?xml version="1.0" standalone='no'?>
<!--\*-nxml-\*-->
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
<name replace-wildcards="yes">oculus</name>
<service protocol="ipv4">
<type>_oculusal_sp._tcp</type>
<port>${port}</port>
<host-name>vr-pc.local</host-name>
</service>
</service-group>
EOF

servicectl restart avahi-daemon
fi
SKIPRESTART
sleep 10
done

Help plz

Edit: duh. When it skips to skiprestart the if is never closed nevermind

https://redd.it/yaf9zs
@r_bash
How to extract volume of active sink

Hi everyone

Trying to extract current volume of active sink. I use this to get active sink name

`pacmd list-sinks |awk '/* index:/{print $3}'

but now i don't know how to extract volume of active sink.

This is pactl list sinks output

Sink #0
State: SUSPENDED
Name: alsa_output.pci-0000_00_1f.3.analog-stereo
Denoscription: Built-in Audio Analog Stereo
Driver: module-alsa-card.c
Sample Specification: s16le 2ch 44100Hz
Channel Map: front-left,front-right
Owner Module: 6
Mute: no
Volume: front-left: 26071 / 40% / -24.02 dB, front-right: 26071 / 40% / -24.02 dB
balance 0.00
Base Volume: 65536 / 100% / 0.00 dB
Monitor Source: alsa_output.pci-0000_00_1f.3.analog-stereo.monitor
Latency: 0 usec, configured 0 usec
Flags: HARDWARE HW_MUTE_CTRL HW_VOLUME_CTRL DECIBEL_VOLUME LATENCY
Properties:
alsa.resolution_bits = "16"
device.api = "alsa"
device.class = "sound"
alsa.class = "generic"
alsa.subclass = "generic-mix"
alsa.name = "ALC257 Analog"
alsa.id = "ALC257 Analog"
alsa.subdevice = "0"
alsa.subdevice_name = "subdevice #0"
alsa.device = "0"
alsa.card = "0"
alsa.card_name = "HDA Intel PCH"
alsa.long_card_name = "HDA Intel PCH at 0xb273c000 irq 147"
alsa.driver_name = "snd_hda_intel"
device.bus_path = "pci-0000:00:1f.3"
sysfs.path = "/devices/pci0000:00/0000:00:1f.3/sound/card0"
device.bus = "pci"
device.vendor.id = "8086"
device.vendor.name = "Intel Corporation"
device.product.id = "9dc8"
device.product.name = "Cannon Point-LP High Definition Audio Controller"
device.form_factor = "internal"
device.string = "front:0"
device.buffering.buffer_size = "352800"
device.buffering.fragment_size = "176400"
device.access_mode = "mmap+timer"
device.profile.name = "analog-stereo"
device.profile.denoscription = "Analog Stereo"
device.denoscription = "Built-in Audio Analog Stereo"
module-udev-detect.discovered = "1"
device.icon_name = "audio-card-pci"
Ports:
analog-output-speaker: Speakers (type: Speaker, priority: 10000, availability unknown)
analog-output-headphones: Headphones (type: Headphones, priority: 9900, not available)
Active Port: analog-output-speaker
Formats:
pcm

Sink #2
State: SUSPENDED
Name: bluez_sink.20_1B_88_1C_97_D7.a2dp_sink
Denoscription: Mi True Wireless EBs Basic 2
Driver: module-bluez5-device.c
Sample Specification: s16le 2ch 44100Hz
Channel Map: front-left,front-right
Owner Module: 24
Mute: no
Volume: front-left: 13099 / 20% / -41.95 dB, front-right: 13099 / 20% / -41.95 dB
balance 0.00
Base Volume: 65536 / 100% / 0.00 dB
Monitor Source: bluez_sink.20_1B_88_1C_97_D7.a2dp_sink.monitor
Latency: 0 usec, configured 0 usec
Flags: HARDWARE DECIBEL_VOLUME LATENCY
Properties:
bluetooth.protocol = "a2dp_sink"
device.denoscription = "Mi True Wireless EBs Basic 2"
device.string = "20:1B:88:1C:97:D7"
device.api = "bluez"
device.class = "sound"
device.bus = "bluetooth"
device.form_factor = "headphone"
bluez.path = "/org/bluez/hci0/dev_20_1B_88_1C_97_D7"
bluez.class = "0x240418"
bluez.alias = "Mi True Wireless EBs Basic 2"
device.icon_name = "audio-headphones-bluetooth"
Ports:
headphone-output: Headphone (type: Headphones, priority: 0, availability unknown)
Active Port: headphone-output
Formats:
pcm


I trying to extract volume of Sink #2

https://redd.it/yanv10
@r_bash
need help plz i want to learn :P



Im Dono ! And i learn bash on linux. im a beginer and i need help for something pretty basic for someone already know bash linux.

I write a simple noscript and i got a problem.

I'm trying to set a variable that detects when I say "games" to tell me "Good games!" and if I say anything else he replies "Good day!"

However, when I try to set the ca variable doesn't work. I leave you screenshots of what I have as an answer.

Btw I don't know how to copy/paste on linux. (I want to specify that I am on windows with ssh access to a Linux Linode in Ubuntu 22.10 version)

Ps** The noscript is in French because I am French speaking. I do my best to translate for you, so be indulgent please.

there is a imgur link to see what happen : https://imgur.com/a/SLVOZoL

Thanks you in advance :P

https://redd.it/yat1ss
@r_bash
Help with custom bash prompt in Termux

Hi guys, I came back to my Termux setup after a year and remembered I had modified the PS1 to use unique colors. I decided to continue down that idea and modify it further, including to have it always print the working directory, like other shells do, since I never have any idea which directory I'm in. I got it working but the only problem is it is only set once when my bashrc runs initially, so to get it to update after cding into a different directory, I need to source it again. Obviously, this is less than ideal. But, I have no idea how to get the behavior I want (immediate updating after cding)

Here is my bashrc https://pastebin.com/eYjWrc4B

Any help would be greatly appreciated. Thanks!

https://redd.it/yaqkd6
@r_bash
How to check if user didnt input any charecters?
https://redd.it/yb0r26
@r_bash
Setting a GSettings parameter as root fails

Hi there,

I'm trying gsettings set org.gnome.desktop.session idle-delay 0 to set the idle-delay parameter (blank screen e.g. during system updates) to zero from a post-install noscript run as root. But the command still fails with the following error message:

>(process:34462): dconf-WARNING **: 02:11:01.329: failed to commit changes to dconf: Failed to execute child process “dbus-launch” (No such file or directory)

After some research, I understand the problem is somehow related to DBUS failing to launch for the root user. And the advice is to either install dbus-x11 (which I don't want to do just for the sake of this operation) or precede the above command line with sudo -u root dbus-launch. But it doesn't help either, still with the same error message.

Any help is highly appreciated! Thank you!

https://redd.it/yb0io6
@r_bash
i need my noscript to SSH into a server....

"ssh user@host" works fine, but how could i get it to put in the password?

i basically need to simulate user input at this point...

https://redd.it/ybpuvu
@r_bash
How to execute Commands in SSH / Bash

I used sshpass to connect, like this:

sshpass -p "password" ssh user@host

But how to actually execute commands? When i enter a command after this, it waits until i disconnect from the server, and then executes it...

https://redd.it/ybr8my
@r_bash
Installomator 10.3 beta - Adobe Pro DC - JAMF

Got a policy in Self service JAMF calling on the Installomator noscript to pull the latest copy of Adobe Pro DC & fails. confirmed that my custom event triggers are correct within my deployment noscript for call out. Checked my Installomator log & get an exit code 20 oppose to 0 with other apps that drop. Encountered same issue in v.9.2 with pulling Adobe Pro DC as well. Attached log notes.

Thoughts?

&#x200B;

https://preview.redd.it/d0oog1y8wnv91.jpg?width=937&format=pjpg&auto=webp&s=18e15211a66a75a3fee9732b65bfd7e32ad12bdd

https://preview.redd.it/jsbvqrx8wnv91.jpg?width=932&format=pjpg&auto=webp&s=48fcfad6cf973cdfaf4a0229ca3f809cd99ae4b6

https://redd.it/ybzd99
@r_bash
simple bash noscript issue

Hey so im trying to exectue a program with a command line option in a shell noscript.

#!/bin/bash
vkquake -basedir /mnt/hdd2/Games/vkquake

Thing is the noscript does not use the option, but if I run "vkquake -basedir /mnt/hdd2/Games/vkquake" in a terminal it works fine and uses /mnt/hdd2/Games/vkquake as the base quake directory.

Is there anyway I can use that option "-basedir /mnt/hdd2/Games/vkquake" from within the noscript? Thanks.

https://redd.it/yc4n1k
@r_bash
How to prevent user from inputting special charecters and spaces/more than one word.

How can I prevent the user form inputting any special charecters such as @#$&/! And so on, as well as preventing any spaces.

And I want to incorporate it like this

read -p "choose" input
if $input = ; then
echo "special charecters and spaces are forbidden"
wait 1.5
else

Thanks in advance!

https://redd.it/yc686m
@r_bash
Need Some Help With My Login Script

Saw a noscript online and thought I would leverage it, I'd like to choose which Windows Manager I'm going to use on login, but also want to trap ctrl-c so nobody bypasses the noscript.

When I log into the gui environments don't notice any issue until I call tmux into my shell, it hangs. Well, not exactly hangs, it brings up tmux but inside tmux commands are not called. For example I can call 'ls' and nothing happens after I push enter.

Edit: checked btop and my login process never quits, it keeps running. How do I instruct it to quit after my choice has been made?

If i remove the 'trap' everything work as expected, and tmux can enter commands because the process quits as expected. But I'd like to keep ctrl-c trapped and still have this process quit after I made a choice.

Not sure how to noscript this correctly, any and all help appreciated

&#x200B;

#!/bin/bash
# ~/.bash_profile
#
[[ -f ~/.bashrc ]] && . ~/.bashrc

setterm --cursor on

##choose twm upon login
## trap ctrl-c first
trap 'login' SIGINT

## login func
login()
{
# ...first let create some varibales
m=$(for p in /sys/class/drm/*/status; do con=${p%/status}; echo -n "${con#*/card?-}:"; cat "$p"; done | rg -i HDMI-A-1 | cut -d ':' -f 2)

if [ "$m" = 'disconnected' ] ; then
H="Hyprland"
else H="env WLR_DRM_DEVICES=/dev/dri/card0 Hyprland"
fi

s="sway"
h="$H"
i="river"
t="tmux -2"
r="systemctl reboot"
o="systemctl poweroff"

if [ -z $DISPLAY ] && [ "$(tty)" = "/dev/tty1" ]; then
echo -ne " \n Hello $(whoami), which one are we feeling right now? "
read twm
case $twm in
"s") echo -ne "\n Ok \e[1;38;1;45m$(whoami), playing it safe with \e[1;36;1;40mSway\e[0m" && sleep .5 && exec $s ;;
"h") echo -ne "\n \e[1;37;1;41mHyprland\e[0m..like it $(whoami) - TWM with some bling" && sleep .5 && exec $h ;;
"i") echo -ne "\n Whatever $(whoami) \e[1;36;1;42mriver\e[0m, complicated and no bling --like whatver" && sleep .5 && exec $i ;;
"t") echo -ne "\n Alighty then ... \n \e[1;30;1;42mTmux\e[0m, you must be in console mode" && sleep .5 && exec $t ;;
"r") exec "$r" ;;
"o") exec "$o" ;;
*) echo -ne "\n WTF!!!, \nyou must be a \e[1;31;1;40dumbass\e[0m" && sleep 1 && logout ;;
esac
fi
}
while :; do
login
read -rn 1 twm
done

https://redd.it/yc6fx1
@r_bash
Creating file from each line in a list?



If i have list in a text file how can i create separate file for each line and insert the line in the text file? For example, if i have this list:

first line
second line
third line
forth line


I want to create four files and insert the text from each line in the file, but i don't want the name of the files to be as the name of the lines of text. Also, i want to add number to each file in increasing order. For example, i want the files to look like this:

file 1.txt
file 2.txt
file 3.txt
file 4.txt

https://redd.it/yc6f17
@r_bash
How to find content in a file and replace the next string

Using bash how do I find a string and update the string next to it for example pass value

`my.site.com`|test2.spin:80

proxy_pass.map

my.site2.com test2.spin:80
my.site.com test.spin:8080;

Expected output is to update proxy_pass.map with

my.site2.com test2.spin:80
my.site.com test2.spin:80;

I tried using awk

awk '{gsub(/\^my\\.site\\.com\\s+[A-Za-z0-9\]+\\.spin:8080;$/,"my.site2.comtest2.spin:80"); print}' proxy_pass.map

but does not seem to work. Is there a better way to approch the problem. ?

https://redd.it/yc9jk3
@r_bash
Writing bash code for array with multiple values

I have a json file which i'm using bash to extract.

sample.json

{"extract": { "data": {"name": "John Smith", "id": 8752, "address": "1 Anywhere Street", "tel": 1234567890, "email": "john.smith@gmail.com" }, { "name": "Jane Smith", "id": 4568, "address": "719 Anywhere Street", "tel": 0987654321, "email": "janesmith@hotmail.com" } } }

and store the value within an array

id=($(cat sample.json | jq -r '.extract.data .name'))

so in the case of ${id[0]} will output John Smith and ${id[1]} will output Jane Smith.

I am intending to store the values in a database (this will be my first attempt) which will be in a similar to that of the json, each object needs to be relative to how it is in the json so it might be better to go with:

data1=($(cat sample.json | jq -r '.extract.data0 | .))

Lets say i have 1000 names to save to my database along with their id's. I'm some advice whether if there a more sensible (more effective) approach on how:

\- Pull the data from Json? will I need to write this 1000 times?e.g

data1=($(cat sample.json | jq -r '.extract.data0 | .))
data2=($(cat sample.json | jq -r '.extract.data1 | .))
data3=($(cat sample.json | jq -r '.extract.data2 | .))
..
data1=($(cat sample.json | jq -r '.extract.data1000 | .))

\-Put the data into the DB from the first array? will the code need to reference the array as:

${data10}
${data11}
${data12}

Would be grateful for a steer in the right direction? - thanks.

https://redd.it/ycexmq
@r_bash
Does Bash have something like Powershell's MenuComplete?

Powershell has a completion function called MenuComplete which displays all completion options and lets you select using the arrow keys. Typing more also narrows down the options. Is there a similar feature in Bash, or is there another shell that can do this?

https://i.stack.imgur.com/nbOkY.gif

https://redd.it/yclc9h
@r_bash
Command out to var

Hi all,

Have experience with noscripting but stumped a bit on bash...

I want to run a command and parse the output to see if someone is logged into a system...

The command is "oc whoami". I thought this would work...

checkLogin=$(oc whoami)

But it still outputs the command when it is run. I tried this but then the var is empty and the output still happens...

checkLogin=$(oc whoami >/dev/null)

Also tried putting the redirect to Dev null outside the parentheses but still get output and blank var

Please help!

https://redd.it/ycqaru
@r_bash