Questions tagged as ['bash']

Bash (Bourne-Again SHell), is the shell used in Ubuntu's command-line interface by default.
Score: 0
pasha19 avatar
Running the same code with -u and +u gives different results
cn flag

I have a fairly large set of scripts that is the initial part of creating some debug/logging logic for bash scripts. There is a considerable amount of code in the system. Fortunately I can demonstrate the different results that I cannot explain when the script is run +u and -u. Set variables as tested using +u become unset variables when run with -u. The variabl.e name in this case is $FUNCNAME

 ...
Score: 0
123MilitaryNerd avatar
Rename a Tab in Thunar?
nl flag

When I have two or more tabs open in Thunar, I'd like to give each tab a custom name instead of the name of the current directory. Is this possible? If not, is there a way I could implement this using a custom action or bash script?

Score: 1
Removed all my bash files in home directory (.zsh, etc.). What to do?
cn flag

By accident ran sudo rm *. in the home directory, and now all bash scripts are gone. I still have one tab opened in terminator which seems to have bash history. What can I do to restore it? When new tabs are created in the terminal, it looks broken.

Score: 0
Abdul Qadir avatar
Issue: bash: /home/abdulqadir/.bashrc: line 116: syntax error near unexpected token `export'
cn flag

After pasting the text at the end of bashrc file I'm having this issue. Please help me in this.

bash: /home/abdulqadir/.bashrc: line 116: syntax error near unexpected token `export'
bash: /home/abdulqadir/.bashrc: line 116: `  fi export ROOTSYS=/home/abdulqadir/root'
Score: 0
'sudo crontab -e' Jobs Are Not Running on Fresh Install of Ubuntu 21.10 (Gnu/Linux 5.13.0-30-Generic X86_64)
br flag

I recently did a fresh install of Ubuntu. I am trying to setup some cron jobs using sudo crontab -e

My crontab is as follows:

# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for ...
Score: 1
bash: `set +m` option does not work when placed in the .bashrc file
it flag

If I enter the command:

set +m

at the end of the .bashrc file, when I run the command:

echo $-

the option m is missing as it should be, but...

If I enter the command:

{ sync & } 2> /dev/null

and then I press enter again without entering any commands, although I removed the m option, the output still appears:

[1]+  Done                    sync

and only when I rerun the command from the  ...

Score: -3
Jacob Simon avatar
Crontab won't run Shell Script
in flag

Im trying to run a shell script with cron every day at 2am

Cron: 0 2 * * * /home/pi/TTD/startTTD.sh

File:

#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/pi/TTD
/bin/sleep 3
./TwoToneDetect71d

File location: /home/pi/TTD

./TwoToneDetect71d is an application

I've tried running it under sudo crontab -e and crontab -e with no luck

Score: 0
bash: set command: enable the options by overwriting the previous ones
it flag

Pretending that the output of $- is this:

hims

If I add options with the set command:

set -B

the output of $- becomes this:

himBs

but I would like it to become this:

iBs

So that it overwrites the previous options.

Score: 1
Find a directory with a prefix in name
do flag

I have one big directory, that contains many subdirectories whose names are staring with 13xxx,10xxx,11xxx and so on. These directories contains text files with a name my_file.txt. Now the problem is, I want to change the files in the directories 13xxx and 11xxx only and don't want to touch files in 10xxx directories. I am trying to search directories with:

[ -d "13*"] && ..
[ -d "13"*] &am ...
Score: 0
Alacritty Color Schemes Not Working
in flag

Color Change for Alacritty Terminal not working. Usually it works by just changing a configuration file and saving.

enter image description here

This started occurring after I used this command:

LS_COLORS=$LS_COLORS:'di=0;35:' ; export LS_COLORS

Which I got from this thread here when I was attempting to change the color of my directories and folders

I have tried deleting and recreating the alacritty.yml file, but it does n ...

Score: 1
Crono avatar
How to exit from snap watch command?
ad flag

I launched a snap install command from one bash terminal and I wanted to see the installation progress in another terminal.

I first ran snap changes to figure out the ID value to watch for, then ran snap watch <ID>. Installation progress showed as expected.

However, when I do CTRL-C or q, the watch command won't quit. Instead it just piles up another watch progress line on the console.

How am I sup ...

Score: 1
Par4o avatar
Find files from timestamps
kr flag

I have a lot of files, of which I need to show only those created in the last 3 hours, and sort this list by date. I tried to do it with the following command:

find /root/shell/copy/ \( -type f -mmin +180 \) | get_crtime | xargs ls -t | head -1

get_crtime is a function created for .bashrc as shown in this example to find out the date of creation for a file.

How can I use the command correctly?

enter image description here

 ...
Score: 1
Pete avatar
Why might Java code run fine manually, but not from a Shell Script?
no flag

Hi have a frustrating problem: On my Ubuntu 22.04 machine, I have some Java/Maven code which I can run manually from the command line:

me@UbuntuV2:~/home/me/path/to/Java/Code$
me@UbuntuV2:~/home/me/path/to/Java/Code$ mvn test
[INFO] Scanning for projects...
[INFO]
[INFO] -------------------< MyCode.java >--------------------
...code runs fine...

This is great, but I need to run this same code fr ...

Score: 0
nightwatch avatar
Systemd Customization On/Off Switch
tr flag

I am hardening various systemd settings for Ubuntu Server 20.04.

However, there are a lot of potential systemd attributes that can interfere with legitimate processes.

Therefore, I would like to set-up bash scripts to quickly activate / deactivate my -all- of my custom systemd service settings,simultaneously, for times when I need to troubleshoot a non-functioning service.

Parameters:
For every service th ...

Score: 0
Pranjal Doshi avatar
How to check if last k commands ran successfully
cn flag

I am running a couple of bash commands and want to check if all of them ran successfully at the end. How should I go about this?
This is what I tried.

$ man # command 1 with exit status 1
What manual page do you want?

$ res1=$? # command 2 with exit status 0
# this also stores exit code of previous code i.e 1

$ res2=$? # storing exit code of previous command i.e 0

# Now I want to check if all previous ...
Score: 0
Dex avatar
How to create a script which runs on startup only by the first boot?
cn flag
Dex

I need a solutions for creating a configuration script which should be executed only by the first boot of the machine. I want to configure new network interfaces through the script with parameters which are inputed by the user. There are various ways to do that. My guess was systemd.

I tried to write a systemd script like this:

[Unit]
Decription=Network Configuration Service

[Service]
Type=simple
Exe ...
Score: 2
KesiScarlet avatar
I can't fix broken packages
af flag

I can't fix this problem. I don't know how. I followed a tutorial on youtube and I downloaded the deb package on this site dev.mysql.com/downloads/mysql and I tried installing it. It didn't work and gave me errors and packages that couldn't be installed.

sudo apt --fix-broken install

This is what I get:

Reading package lists... Done
Building dependency tree       
Reading state information... Don ...
Score: 0
donna_unsworthcomcastnet avatar
How to add quotes to second element of a string after comma in a text file bash
bt flag

File contents:

1234,/Product/number 234567
2456,/Product/number 456789

and so on...many lines

Want the the output as follows:

1234,"/Product/number 234567"
2456,"/Product/number 456789"
Score: 0
david david avatar
Running sudo in a torified shell
in flag

I am running a torified shell (. torsocks on) and for some reason I am unable to run commands with sudo privileges. I get the following error:
bash: /usr/bin/su: Operation not permitted.

I've tried adding the debian-tor user to the sudo group and can't seem to find anything useful on the internet.

This is using Ubuntu 20.04 LTS Server Edition and I've also tried it out with the latest stable edition of Ka ...

Score: 2
How do I open a terminal with another user name?
id flag

Whenever I open the terminal, I want to login as another user (another_user). I tried putting the below in my .bashrc, but it prompts me for a password everytime I open the terminal.

# in .bashrc
su - another_user

Question: how do I pass another_user's password as a text input in .bashrc so that I don't have to type it every time the terminal opens?

PS: don't worry about security issues.

Thanks.

 ...
Score: 0
BurstBass BurstBass avatar
Read logs real time with bash
be flag

I have this in the system logs:

Feb 27 02:53:51 Latitude-E6430 rsyslogd: action up   7
Feb 27 02:53:51 Latitude-E6430 rsyslogd: action down B
Feb 27 02:53:51 Latitude-E6430 rsyslogd: action up   U
....etc

I want to make a script that is monitoring the logs full time as a service, but I don't know how to do the condition.

1 - That when you read, line by line, store it in a variable.

2 - read variable ...

Score: 1
mohamed wael thabet avatar
gsutil: No such file or directory on startup
in flag

I have VM that runs on linux 18.04.01 and that executes a startup script which includes gsutil :

#!/bin/bash
set -ex
source bin/ci/colors

composer run-script --no-dev build-parameters

gsutil -q cp "gs://gcp-myproject/myappname/parameters.yml" "app/config/parameters.yml"

bin/console cache:warmup --no-interaction

that sometimes (let's say 1 or 2 times out of 3) fails with this error :

line 7: /sn ...

Score: -2
tor.service start request repeated too quickly error
pl flag

I'm using tor service for my script but I get this error:

 The job identifier is 17084 and the job result is failed.
Şub 26 03:12:11 Ugroon systemd[1]: tor.service: Start request repeated too quickly.
Şub 26 03:12:11 Ugroon systemd[1]: tor.service: Failed with result 'start-limit-hit'.
░░ Subject: Unit failed
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support
░░ 
■...
Score: 0
How to download files from text file
co flag

I have multiple text files such as a0001.txt, a0002.txt...upto a0900.txt containing direct image links https://example.com/photos/example.jpg

I want to batch download all links from a0001.txt to a0001 folder and so on in respective folder names as text file.

Links must be download in order so Images renamed with prefix. For sorting purposes.

What I tried was below. But it downloading one file at a ...

Score: -4
Command definition syntax
us flag

What is the name and where I can find info about syntax that defines commands:

cmake [{-D <var>=<value>}...] -P <cmake-script-file> [-- <unparsed-options>...]

What does [] , {} and ... means in this definition. I have feeling, that [] means optinal, but this means that -P should persist always?

Score: 0
Manav Ghai avatar
Cannot run bash script
cn flag

I tried to make a bash script to open a file in VS code but it is giving the error:

Bash: ./open.sh: Permission denied

This is the script:

#!/usr/bin/bash
code  $1
Score: -2
nobody avatar
When creating a file naming template for core dump can you modify the time specifier from unix epoch time to human readable form on the fly
cn flag

I read the man core and man date pages and four quality webpages on the topic core dumps. I've been studying and practicing making core dumps for four days now.

The question is well stated in the title of this post.

Note: when I refer to 'core' I also am referring to the kernel parameter kernel.core_pattern and will call it an environment variable. I call it an environment variable because it acts l ...

Score: 0
Mathan Narthan avatar
Getting a syntax error when running the test.sh file "./test.sh: 36: Syntax error: end of file unexpected (expecting "done")"
cn flag

I'm getting this syntax error when running the test.sh file:

./test.sh: 36: Syntax error: end of file unexpected (expecting "done")

test.sh:

#!/bin/sh

# WebHook
url="DiscordWebHook"
hostname="TestingSvr01"
PublicIP="My IP"

# check current disk usage
df -H | grep -vE '^Filesystem|tmpfs|cdrom|loop' | awk '{ print $5 " " $6 }' | while read output;

# assign variables
do
  #echo $output
  used=$(echo ...
Score: 0
Fernando Olvera avatar
How to rename list of files to a partial same name plus numbered sequence before extension
ph flag
mv MIPS_236_CONTROLLING_HIGH_BLOOD_PRESSURE_CA_20221701_Denominator_P1_1.csv ../MIPS_236_CONTROLLING_HIGH_BLOOD_PRESSURE_CA_20221701_Denominator_1.csv
mv MIPS_236_CONTROLLING_HIGH_BLOOD_PRESSURE_CA_20221701_Denominator_P2_1.csv ../MIPS_236_CONTROLLING_HIGH_BLOOD_PRESSURE_CA_20221701_Denominator_2.csv
mv MIPS_236_CONTROLLING_HIGH_BLOOD_PRESSURE_CA_20221701_Denominator_P2_2.csv ../MIPS_236_CONTROLLING_HIGH_ ...
Score: 0
SumNeuron avatar
adduser fails with error code 1 and then error code 6
am flag

I am trying to add a new admin user to a system. I tried via the GUI but it gave error code 1. I went to the terminal and tried:

$ sudo adduser <username> sudo
adduser: The user <username> does not exist.

$ sudo adduser <username>
Adding user `<username>' ...
Adding new group `<username>' (1001) ...
Adding new user `<username>' (1001) with group `<username>' ...