Jump to content

bash script linux stuff

Go to solution Solved by 0x21,
#!/usr/bin/env bash

file="/sys/class/backlight/intel_backlight/brightness"

var=$(cat "$file")
var=$((var - 100))

echo "$var" |  sudo tee "$file"

 

i wanted to make a bash script that ran when i hit the brightness keys on my keyboard to lower and raise the brightness. i am new to bash scripting so try to keep it simple

 

my jank script 

                       

#!/bin/bash
var=$(cat /sys/class/backlight/intel_backlight/brightness)
echo $var
var= expr $var - 100
destdir=/sys/class/backlight/intel_backlight/brightness
sudo echo "$var" >> "$destdir".

 

i get a permissions error on the last line every time

Spoiler

CPU: 5800x

GPU: 1070ti

HDD: Seagate 3TB
SSD: 1TB WD NVME

RAM: 32GB ddr4 3200

HEADPHONES: DT990 pro 250ohm limited edition black

MONITER: BenQ xl2536

CASE: s340 elite hyperbeast

KEYBOARD: nk87- zilent switches

MOUSE: G403 Hero

 

Link to comment
https://linustechtips.com/topic/1018947-bash-script-linux-stuff/
Share on other sites

Link to post
Share on other sites

17 minutes ago, Domi-Nate said:

sudo echo "$var" >> "$destdir".

You get a permission-error, because echo happens as root, but the redirection to the file still happens as the original user. Use

echo "$var" | sudo tee -a "$destdir"

 

Hand, n. A singular instrument worn at the end of the human arm and commonly thrust into somebody’s pocket.

Link to post
Share on other sites

now i get no permission error but it changes then reverts so nothing happens

 

nate@nate:~/Desktop$ bash brightnessup
7000
6000
7000
 

i want it to delete the number on the file and replace with the var so that the brightness goes down... what am i doing wrong

Spoiler

CPU: 5800x

GPU: 1070ti

HDD: Seagate 3TB
SSD: 1TB WD NVME

RAM: 32GB ddr4 3200

HEADPHONES: DT990 pro 250ohm limited edition black

MONITER: BenQ xl2536

CASE: s340 elite hyperbeast

KEYBOARD: nk87- zilent switches

MOUSE: G403 Hero

 

Link to post
Share on other sites

when i set 

1 hour ago, WereCatf said:

echo "$var" | sudo tee -a "$destdir"

to 

echo "4000" | sudo tee -a "$destdir"

it sets but i want the ability to have steps of 100 and every time i run it reduces the number by 100
Spoiler

CPU: 5800x

GPU: 1070ti

HDD: Seagate 3TB
SSD: 1TB WD NVME

RAM: 32GB ddr4 3200

HEADPHONES: DT990 pro 250ohm limited edition black

MONITER: BenQ xl2536

CASE: s340 elite hyperbeast

KEYBOARD: nk87- zilent switches

MOUSE: G403 Hero

 

Link to post
Share on other sites

I just wiped my computer so I could set up duel boot with kali and Ubuntu but I’m gonna mark this as solved for now...

Spoiler

CPU: 5800x

GPU: 1070ti

HDD: Seagate 3TB
SSD: 1TB WD NVME

RAM: 32GB ddr4 3200

HEADPHONES: DT990 pro 250ohm limited edition black

MONITER: BenQ xl2536

CASE: s340 elite hyperbeast

KEYBOARD: nk87- zilent switches

MOUSE: G403 Hero

 

Link to post
Share on other sites

aight ive tested it and the script works thx mshaugh

Spoiler

CPU: 5800x

GPU: 1070ti

HDD: Seagate 3TB
SSD: 1TB WD NVME

RAM: 32GB ddr4 3200

HEADPHONES: DT990 pro 250ohm limited edition black

MONITER: BenQ xl2536

CASE: s340 elite hyperbeast

KEYBOARD: nk87- zilent switches

MOUSE: G403 Hero

 

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×