Skip to main content

Questions tagged [bash]

Questions specific to GNU’s Bourne Again SHell, as opposed to other Bourne/POSIX shells. For questions about Unix shells in general, use the /shell tag instead. For shell scripts with errors/syntax errors, please check them with the shellcheck program (or in the web shellcheck server at https://shellcheck.net) before posting here.

15 votes
5 answers
1k views

How can UserA programmatically replace a text string within a file they own that's located in /etc?

A non-root linux user owns a text file that's located in /etc, where the non-root linux user does not have permission to create files. The non-root linux user can edit the file manually via vi without ...
Tortoise Pirate's user avatar
1 vote
1 answer
113 views

What is PS1 prompt \[\e]0; vs \[\e]2; , it looks like one is for title name of tab, one is for title name of windows

here is my ps1 does someone know documents about this? export PS1='\[\e]0;YYY@\h:\w\a\]\[\e]2;XXX\W\a\e[32;40m\]\[\e[36;40m\]$?\[\e[31;40m\]\D{%d}\[\e[35;40m\]\D{%H%M}\[\e[36;40m\]\W\[\e[32;40m\]>\[...
user3073309's user avatar
-3 votes
1 answer
81 views

How to split a number into unequal parts in Bash

Hypothetic example: There is a number that I will split into x parts (smaller numbers, in a range you see in the example). I need a way, ideally a one liner for the Linux Bash, to split a large number ...
user447274's user avatar
-2 votes
1 answer
71 views

How do I get lastlog timestamps in a generic format?

I have multiple Ubuntu machines in different locations. I want to collect the last login information from these machines. However, when I use the lastlog command, it returns dates in different formats....
Cong Thanh Huynh's user avatar
0 votes
1 answer
37 views

gpg suddenly won't ask for password, "cancelled by user"

Suddenly, gpg won't ask for password when trying to decrypt file and instead says "cancelled by user". I have already tried.. GPG_TTY=$(tty) export GPG_TTY with no effect. I get the ...
slowcoder's user avatar
1 vote
1 answer
26 views

`pushd` inside a while loop from file contents does not behave the same depending on read method [duplicate]

I'm pushing directories to my stack using a while loop that reads the contents of a file. I've tried two approaches that should be equivalent, but they behave different. Approach 1 export ...
Jorge Ricardo Alonso Fernández's user avatar
3 votes
2 answers
282 views

How do quotes work in bash regex regarding reserved characters?

Is there any special bash reserved characters in bash regex expression? ex: eg: if [[ $url =~ ^https:\/\/www\.youtube\.com\/playlist\?(.+&)?list= ]]; then echo "URL matches the regex"; ...
Nor.Z's user avatar
  • 133
13 votes
3 answers
1k views

Why does setting a variable readonly in the outer scope prevent defining a local variable with the same name?

I've found nothing about this in all my searching. In the code below, Bar1 acts like I'd expect a "regular" variable to act (since help declare says that -g is only "seen" in ...
RonJohn's user avatar
  • 1,134
0 votes
1 answer
60 views

How to add categories in `free` command

I can extract the amount of memory used by running the following two commands from terminal: free -h | awk '/^Mem:/ {print $3}' This shows the used memory, e.g. 4.8Gi. free -h | awk '/^Mem:/ {print $5}...
ellat's user avatar
  • 37
-1 votes
1 answer
85 views

Bash deploy script only works the first time?

This script works perfectly the first time after starting it but when it's done it only continues to output zip_count: 0 afterwards. There seems to be some strange cache? I run the script inside Git ...
OZZIE's user avatar
  • 99
2 votes
1 answer
48 views

Is there a way to `exec` a pipeline or exit shell after launching a pipeline?

I'm writing a shell wrapper script that is supposed to act as a pager (receiving input on stdin and performing output on a tty). This wrapper prepares environment and command lines, then launches two ...
intelfx's user avatar
  • 5,467
-2 votes
0 answers
75 views

Searching for a bootable USB Linux image to run a single bash script without user interaction

I'm looking for a lightweight Linux distribution that can be booted from a USB device with the sole purpose of executing a single bash script and then shutting down automatically. My requirements are: ...
DPRCode's user avatar
2 votes
2 answers
56 views

set -o xtrace for just one line? [duplicate]

bash 4.4.20(1) on RHEL 8.4. set -x ; ./blarge ; set +x works, of course, but it's just that much more stuff to remember to remove when you're finished. And gets sticky if you're running ssh, sudo, ...
RonJohn's user avatar
  • 1,134
-2 votes
4 answers
135 views

Getting output of /usr/bin/time in CSV format

I am using gawk to parse the output of macos' /usr/bin/time into CSV format as shown below. The problem is that gawk is returning the 'involuntary context switches' value for 'voluntary context ...
jonathannah's user avatar
1 vote
1 answer
82 views

Shell script to run command and show output in notification box

I have command line utility that generates text strings, by running a command within the directory: ./Utility -P it prints output on terminal. How to make a shell script showing the generated string ...
minto's user avatar
  • 533

15 30 50 per page