Questions tagged [bash]
Bash (Bourne-Again SHell), is the default interactive user shell used in Ubuntu. Use this tag for questions specific to Bash, as opposed to generic POSIX shells.
11,214
questions
0
votes
0
answers
334
views
My .profile and .bashrc files are not read
When I run `clang'I get the error message
command clang not found, but can be installed with:
sudo apt install clang
Both .profile and .bashrc are not read.
Below is my .profile file
# ~/.profile: ...
1
vote
3
answers
71
views
Make if statement true when variable matches one of the strings in a list
I have a command that will output the following (curl -sSL $location | grep -o "title\=\".*\"\ agent" | grep -o "\".*\"" | grep -o "[a-zA-Z0-9].*[a-zA-Z0-9]...
0
votes
0
answers
116
views
bash, while loop, source file return error in 1 case; how to catch to variable?
I have this part of code.
while IFS=' ' read -ra var
do
source SCRIPT 2>&1 | tee -a $log
done <<< $main_config
SCRIPT
ssh -i id_rsa "${var[5]}"@"${var[1]}" -...
0
votes
0
answers
582
views
How to redirect service stdout to terminal console?
A service is created and here is the ExecStart:
ExecStart=/bin/sh -c "/home/admin/bin/besu/bin/besu --config-file=/home/admin/bin/besu_network/node1/config.toml"
This command start a ...
0
votes
1
answer
183
views
How to get part of the filename using (basename "${video%.*}") in bash script?
I have a set of videos scalled xxxyyys.mp4, each filename ends with s. I want to execute a script that takes only the name upto xxxyyy for the argument basefile.
So far, what I have is
for video in ...
0
votes
0
answers
22
views
command aliasing in ~/.bashrc doesn't work after sourcing or rebooting [duplicate]
I want to add an alias to my ~/.bashrc such that when I use killp it kills the python process(es) that use GPU.
I am not sure why neither of these commands work. I have sourced my bashrc using source ~...
2
votes
1
answer
397
views
Run multiple bash script when ubuntu starts
I have 3 bash commands/files that I need to launch on seperate terminals when my ubuntu 20 machine startups
$ ./script1
$ ./script2
$ ./script3
I want all these 3 script to run in each separate ...
1
vote
0
answers
198
views
Bash terminal shows: "update-alternatives: error: no alternatives for javac" on start and when I try to run a bash script
Title pretty much says it. Every time I open a terminal, I get the message: "update-alternatives: error: no alternatives for javac". I have no idea what this means, maybe something with ...
3
votes
2
answers
760
views
locate command and globbing of shell
From locate man page:
If --regex is not specified, PATTERNs can contain globbing characters. If any PATTERN contains no globbing characters, locate behaves as if the pattern were *PATTERN*.
Now, see ...
2
votes
2
answers
272
views
Sequential numbering on file name (Continue numbering on multiple commands)
I'm encoding multiple music videos to HEVC and backing them up on 1fichier using rclone. Since these are small files (100 MB on average) and when I upload them in bulk I get a Flood detected: IP ...
1
vote
1
answer
164
views
Drop cache job with certain condition gives error in crontab
I'm trying to apply a cronjob to drop cache that checks for a certain condition every minute and if the condition applies then it executes, also I don't want jobs to overlap if it takes longer than a ...
0
votes
1
answer
802
views
How to replace terminal title using sed in PS1 prompt string
I've been at it for > 1 hr. and can't figure this out. Here's my PS1 prompt string:
$ echo $PS1
\$SHLVL:2 \e[7m$(gs_git_show_branch)\e[m\n\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\...
0
votes
1
answer
108
views
What is the best way to automate my linux setup
At work, I had to rebuild my WSL a number of times and I was wondering what will be the best way to automate my Ubuntu setup. For .dotfiles files, I'm using the bare-git approach (https://www....
-1
votes
2
answers
84
views
Whats the difference between a pipeline operator and $()? [duplicate]
mint@mint-VirtualBox:/$ ls -l $(which cp)
-rwxr-xr-x 1 root root 153976 Sep 5 2019 /usr/bin/cp
mint@mint-VirtualBox:/$ which cp | ls -l
total 1043228
lrwxrwxrwx 1 root root 7 Jan 21 15:09 ...
0
votes
1
answer
124
views
How work with conditionnal stdout/stdin
Initially, I want to check if a service is running or not in a bash script automaticly.
Then I found a command I don't understand but which work well :
/usr/sbin/service mysql status || /usr/sbin/...
1
vote
0
answers
174
views
udev rule launches bash script at hotplug but not at coldplug/reboot
basically this udev rule at boot time , but I read somewhere that it was the systemd daemon that handles all the coldplug while udevd handles only the hotplugs.
How to do it with the linux systemd way ...
-1
votes
1
answer
359
views
sh -c '...' sh {} not working when using if statement and having ' in the filename
I have the following simplified script:
find /home/cas/plex-media/series/ -type f ! -name "*.srt" -exec sh -c '
file=$1
if [ if-statement using $file ]; then
echo "true&...
0
votes
1
answer
988
views
make a script that open two terminal and start projects [duplicate]
I would like to create a script that navigate to 2 project folder, and execute 2 terminal that remain open, so that I don't have to do it everyday.
I tried the following :
#!/bin/bash
cd Repository/...
2
votes
1
answer
534
views
How can I convert netstat output to a variable
netstat -an | grep :443 | grep -v TIME_WAIT | wc -l
How do I convert this retunring value of 171 to a variable foo so that If I enter $foo it will return 171.
5
votes
1
answer
8k
views
Using xargs and variables
Hey I have a question.
This is the command that I'm using (at the place of echo $file is a different command. I simplified it):
find /home/cas/plex-media/series/ -type f -name "*" ! -name &...
0
votes
0
answers
265
views
How to correctly sort by numbers when having numbers higher than 9
I have a simple question.
When I have a list of numbers and use sort, I get the following result:
10
11
12
7
8
9
Because 1 is lower than 7, it sorts 10 lower than 7. How can I make it so that it ...
2
votes
2
answers
527
views
How can I alias a dot string (e.g. '...' to '../..')? [duplicate]
I'm trying to have a shortcut for going back a few dirs. Something like "cd ...." == "cd <number of dots - 1> * '../'"
I tried doing alias '...'='../..' && cd ... ...
0
votes
2
answers
2k
views
Cancel zenity button usage
so a pretty straight forward question , on zenity theres is 2 buttons on each page , ok and cancel . with my script i manage to assign the zenity code to a variable where i can pick a date for my ...
0
votes
0
answers
887
views
what NF stands for in awk?
I know NF is the last element, as explained here:
NF is a predefined variable whose value is the number of fields in the current record. awk automatically updates the value of NF each time it reads a ...
1
vote
4
answers
1k
views
`ls -l` output duration instead of date/time eg "5 mins"/"6 hours"/"7 days" etc?
If I last modified a file 5 minutes ago, is it possible to make ls-l output something like "5 mins" instead of the actual date/time?
1
vote
1
answer
1k
views
How to correctly set environment variable (which may not exist)
I want to set an environment variable LD_LIBRARY_PATH which may or may not exist (it does not seem to exist currently, but I'm not sure if it will at some point).
I have successfully managed to set my ...
3
votes
1
answer
2k
views
create directory structure from tree command output
I have few tree command output of some directory structures (in text files). It looks something like:
% cat tree.txt
.
├── grandpartest
│ └── partest
│ └── test
│ ├── empty-asciidoc-...
1
vote
0
answers
38
views
Is there any bash script to find the difference of two directories and copy the difference to next third directory?
Actually I need a script that compare the content of two directories and copy the difference to next directory. Suppose I have dir1 which contains file1 and file2; dir2 which contains file1 then the ...
2
votes
1
answer
526
views
Inotifywait apply regex pattern on changes in a file
Requirement: Alert if there is any package installed or removed in the ubuntu server.
For this requirement, I'm trying to use inotifywait to continuously monitor dpkg.log, if there are any changes ...
0
votes
1
answer
395
views
Dealing with spaces in filenames
I have written the following bash function to easily open files from the command line with their default application:
## Open files with their default application
function open {
# If no arguments ...
1
vote
1
answer
138
views
Ubuntu 18.04-Replace default screen lock behavior with custom shell script
I'd like to override the default Ubuntu screen locking behavior. I have a shell script set up which does exactly what I want it to do when I run it manually, however, I cannot seem to find any way to ...
0
votes
1
answer
49
views
Bash script creates terminal that persists for further work
Some similar posts did not clear up this question:
How do I create a terminal from inside a bash script,
giving initial commands (e.g. df, pwd etc) and
allowing me to keep working on it after the ...
0
votes
0
answers
47
views
Is there an way to rotate a specific window from terminal?
I am using cava music player.So since cava by default appears horizontally , i wanted to change the orientation how cava appears to vertical or tilt the window so that it appears vertical.Is there any ...
2
votes
2
answers
903
views
How to remove slightly modified duplicate images?
I have thousands of images that I have made in my phone and DSLR over last couple of years and never given a thought about photo management until recently and it is a mess now. I used
fdupes -r . > ...
0
votes
2
answers
2k
views
Restrict users to their home directory
I'm setting up beginner CTF (Capture the flag) in a Linux environment.
I will have questions that will tell the user to run specific commands.
The issue I'm having is restricting the user to a ...
1
vote
1
answer
209
views
Scripts that detects kernel activity and reboots when kernel freezes
I'm running a machine that has a GPU running that sometimes causes the machine to freeze. When
I look at syslog file, it says that the kernel is hung:
"echo 0 > /proc/sys/kernel/...
1
vote
0
answers
96
views
Bash script executable manually but only partially via udev rule
I'm on Ubuntu 18.04 LTS and I wrote a script to take pictures and send an email with ssmtp when someone removes a USB device from my computer.
the udev rule works fine and execute the script but only ...
0
votes
1
answer
781
views
How to add special characters in ~/.bashrc file?
I am trying to make a bash alias to grep for Git conflicts within files after a merge occurs. Usually on the command line with bash shell, I run grep -nr '<<<<<<<', where the ...
0
votes
1
answer
144
views
Help me understand this redirection and the read built-in?
I have a backup script which I'm asking now to (offer to) call a git pull script before actually running the syncs (when run interactively). The syncs are done thusly:
rsync aiSP --delete
The ...
3
votes
2
answers
2k
views
How to trigger an alias over sshpass/ssh?
I have a server with an alias as follows:
~/.bash_aliases
alias update='sudo apt update && sudo apt -y upgrade'
Now I want to create a shortcut from my desktop that can simply trigger this ...
-1
votes
1
answer
434
views
Should I use aliases or modify $PATH?
A made a bash file called foo, containing a few instruction and I often use it. I want to call it using $ foo
I could either add export PATH=$PATH:/path/to/foo to ~/.bashrc
Or add alias foo='path/to/...
1
vote
0
answers
651
views
Zenity Calendar Input
So i am trying to do a Calendar which can be used as a notepad for each day, like a reminder.
I was wondering if there is a way that when the user click on a date , the program open an --entry text ...
0
votes
1
answer
1k
views
zenity file-selection how to get list items as you choose
I have a bash script that use zenity as GUI.
I need to get a list of files in the same order as I select them.
I use --file-selection option and working fine but it put in the output variable always ...
0
votes
1
answer
128
views
awk -v var=$var /var/ is not working as expected
Portion of file:
<style:style style:name="P15" style:family="paragraph" style:parent-style-name="Table_20_Contents">
<style:paragraph-properties fo:text-...
0
votes
0
answers
83
views
'q-text-as-data: command not found' error in a Bash script?
I am a Linux novice, and I am currently trying to run a Bash Shell Script (see the very bottom) that manipulates files (code snippets) using the Windows 10 Linux Subsystem, but the script keeps ...
2
votes
2
answers
3k
views
replace text with part of text using regex with bash perl
For example I have this output:
string1 anynameveryveryverylong string2
string1 othernameveryveryverylong string2
I want truncate the name to the first ten characters:
string1 anynamever string2
...
0
votes
0
answers
20
views
How to remove Gekodriver from Path
I am new to Ubuntu (Ubuntu Mate) and wanted to continue coding.
I reached a site which had many links an I had to click all so I made a Bot, for that I installed GekoDriver after I was done I wanted ...
0
votes
1
answer
496
views
Why doesn't screen see my alias?
I have this alias in my .bashrc
...
...
alias server1='for line in `seq 1 10`; do echo "Running server 1: "$line; sleep 1; done'
server1 command works as it should in terminal. But I'm ...
2
votes
1
answer
2k
views
Bashdb in Ubuntu 20.04
I cannot find bashdb in Ubuntu (MATE) 20.04 repos, i.e apt returns nothing when searching for 'bashdb'. I'd rather avoid installing it from source. Do you know why it was not added to the repos?
0
votes
0
answers
56
views
Please what means this
Iam writting .sh script for uploading aplication on server and have correction of echo fail to download $...
c=country like cz,us,sk etc
change of my echo fail to download $ on : echo cant find ${c^^}...