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.

Filter by
Sorted by
Tagged with
0 votes
1 answer
49 views

How can I exclude things from .bash_history? [duplicate]

Every time I run a program using the VSCode debugger, a line such as /usr/bin/env /bin/sh /tmp/Microsoft-MIEngine-Cmd-agft2qoj.y5y or /usr/bin/env /bin/sh /tmp/Microsoft-MIEngine-Cmd-1ai4zqj4.nob ...
Mark's user avatar
  • 4,294
1 vote
3 answers
69 views

How can I add a property in the end of the object (text manipulation)

I'm doing some text manipulation and I want to add a property (at the end) to an object named "object" that is inside a configuration file e.g . . object = { "one": "one&...
kyles's user avatar
  • 33
1 vote
1 answer
33 views

Retrieve large number of files from remote server with wildcards

I'm trying to download a large number of files from a remote server. Part of the path is known, but there's a folder name that's randomly generated, so I think I have to use wildcards. The path is ...
Mauricio Chavarriaga's user avatar
1 vote
3 answers
443 views

How to sort files by size in bash script?

I want to loop over all files in directory on macOS and perform some operations on each file, and do this based on their size, going from big to small. To create a list I can loop over I do this: ...
d-b's user avatar
  • 1,937
1 vote
1 answer
52 views

Remove all files, but write protected [duplicate]

In the folder there are files with write permission and without it. I need to remove only files which have write permission. When I simply do rm * it prompts confirmation for every write-protected ...
Alex Anushat's user avatar
-2 votes
2 answers
79 views

Extracting role from string in variable [closed]

I have a variable which could either be var=Role or var=AdminRole. I want to be able to do the following: if $var = "Role" then set role variable as $var else if $var = "AdminRole" ...
gdba's user avatar
  • 1
-1 votes
1 answer
71 views

How would I do string comparison in awk with variable strings on both sides?

As a follow-up to my previous question, how would a similar string comparison be made when there are mutable characters on either side of it in the document? As an example: # test,date "test1&...
T145's user avatar
  • 213
2 votes
1 answer
141 views

Awk: Comparing passed Bash variables with column values

Using this example: #submission,date "test1","22 April 2024" "test2","24 April 2024" "test3","25 March 2024" "test6","01 ...
T145's user avatar
  • 213
0 votes
1 answer
43 views

Use grep to search stdout, without replacing stdout

At the moment, I have this in a wrapper script: 2>&1 ./update.sh | ts | tee -a ./update.log and this in update.sh: if apt full-upgrade -y | grep linux-headers then echo echo Need to ...
AaronD's user avatar
  • 153
0 votes
1 answer
57 views

Unable to get cURL command to run within a script with variables

I have what I thought was a simple script: #!/bin/sh URL=myserver:9443 myCmd="curl -sS -k -X 'POST' 'https://" myCmd+=$URL myCmd+="/SKLM/rest/v1/ckms/accessToken' " myCmd+="-...
NCDeveloper's user avatar
0 votes
2 answers
66 views

extract a column from the command output even if it blank bash

I am trying to extract 2nd column from a command output For example: $ sudo /usr/sbin/pvs PV VG Fmt Attr PSize PFree /dev/sdc1 vgswap lvm2 a-- 16.00g 0 /dev/sdc2 ...
Vija200's user avatar
0 votes
1 answer
26 views

Keep restarting an application in an interactive session after a short time

So I'm aware that this is a somewhat convoluted usecase with probably not many practical applications, so unfortunately I wasn't able to find many helpful pointers so far. Basically, I would like to ...
RobinFood's user avatar
1 vote
1 answer
46 views

bash completion only for first non-option word?

I have a program, say foo, like many others that takes command-line arguments of the form: foo [ options ] command ... where options are zero or more short (e.g., -s) or long (e.g., --long) style ...
Paul J. Lucas's user avatar
0 votes
0 answers
41 views

How to show path after cd command with CDPATH set?

I came across this question and showing the current path after cd is exactly what I'm looking for. However, I can't manage to get this behavior. What I've tried is this: export CDPATH='.:/home/...
Alexander Zeitler's user avatar
0 votes
1 answer
28 views

Permission denied when running a mv command as user after entering into sudoers file

I have a user which needs to move a file to a dated folder. I have an entry into the sudoers file as follows: backupuser ALL=(ALL) NOPASSWD: /usr/bin/mv /var/lib/pgsql/base_backup/*.tar.gz /var/lib/...
Dale's user avatar
  • 3
0 votes
1 answer
59 views

How do i get the bash command below to stop echoing these bash alias not found errors?

I think these bash commands were created with the intention of increasing htops refresh interval, cant remember where i found them. However I have since figured out all that was needed to do to get it ...
bob king's user avatar
-2 votes
1 answer
66 views

Behavior of truncating multiple slashes in paths stemming from glob pattern matching

From my limited research it seems that in bash, any multiple slashes after a glob pattern are truncated, like so: echo ////[h]ome////user////Desktop////test//// # outputs ////home/user/Desktop/test/ ...
GhtGhoster's user avatar
0 votes
1 answer
34 views

How to detach a piped command from the terminal?

I want to allow the leading program(s) to operate in a standard manner and detach from the terminal once a graphical application launches. In this example fzf reads paths from a file, feeds the ...
user598527's user avatar
2 votes
1 answer
53 views

Where do I find the specs for bash's _longopt autocompletion?

I like to have shell completion for as many commands as possible. I write a fair amount of shell-scripts that take a lot of different parameters, and it's a life-saver to have the completion just work....
Popup's user avatar
  • 564
0 votes
1 answer
44 views

Replacing variable correctly in alias function

I'm trying to create an alias function to remove inputted line from file: function remove_line(){ line_to_remove="'s/^"$1"$//g'" sed -i $(line_to_remove) my_file } ...
ellat's user avatar
  • 37
2 votes
3 answers
60 views

can nohup and disown both still let program run after exiting the shell

I'm discovering the difference between nohup and disown in Ubuntu's bash. I have while.py. import time while True: print(1) time.sleep(1) First, I used ssh to connect to my ubuntu server and ...
Kartone's user avatar
  • 41
-1 votes
1 answer
55 views

Output of loop variable shows different value than expected

Imagine I have two folders in my current working directory: back/ and front/. I am trying to enter inside each of them and do some stuff. From the simple script below: for dir in */ ; do echo &...
Rigel F. do C.'s user avatar
0 votes
0 answers
187 views

zsh module command not found

I recently switched from bash to zsh on CentOS 7. I am using oh-my-zsh I'm encountering an issue where modules cannot be loaded from a script. When I manually load the module in the login shell, it ...
Adupa Vasista's user avatar
3 votes
3 answers
699 views

How may I find the string length of the index number of a bash array?

In bash, suppose some function generates a simple array of unknown length. The array will be transformed and printed on screen: each line with its little index number next to it to pick from it. Space ...
Vita's user avatar
  • 301
3 votes
1 answer
253 views

SIGPIPE and bash pipefail

I am trying to better understand SIGPIPE on linux. I ran this experiment: { ls -al /tmp/ ; echo "$?" 1>&2 ; } | head and it echos 141 which I understand is an exit code that is given ...
Dave Butler's user avatar
2 votes
1 answer
45 views

Parallel for-loop in bash with simultaneous sequential execution of another task with dependencies on the parallelized loop

In my bash script, I need to execute two different functions, taskA and taskB, which take an integer ($i) as an argument. Since taskB $i depends on the completion of taskA $i, the following ...
Schnarco's user avatar
  • 121
0 votes
0 answers
41 views

"[" displayed as "Ä" and "]" displayed as "Å" in remote terminal from vscode

I did the following things in VSCODE: remote ssh into a remote virtual machine; opened a terminal; typed some characters into the terminal. I then noticed that [ is displayed as Ä and ] is displayed ...
Ziqi Fan's user avatar
  • 237
0 votes
1 answer
44 views

ssh fails only when multiple arguments are stored in a string

I am writing a bash script on Raspberry Pi OS (based on Debian 12 Bookworm). The script tries to do something like ssh "$args" "$user"@"$ip" 'command' From what I have ...
jitter's user avatar
  • 5
0 votes
0 answers
41 views

Find youngest file in a dir easily [duplicate]

Is there a bash-command that gives my the youngest file of a directory. Or even better the youngest file that matches a given pattern. The best I can think of is this. ls -t | head -n1 or for a ...
chris01's user avatar
  • 595
1 vote
0 answers
21 views

How to get user input in dialog --tailboxbg --gauge?

I have a script I run on a macOS machine, where I wish to show a gauge bar and tail the output from the script itself at the same time. I currently use this command, and it works well: #!/bin/bash ...
AnoE's user avatar
  • 675
1 vote
1 answer
29 views

How to Set Up Individual Bash History Files for Each Container Alongside a Unified History File?

In my current setup, all of my bash histories are stored in a single file, which is pointed to HISTFILE. This history includes a history of the host system and all containers. Along with this history, ...
Compiled's user avatar
-2 votes
1 answer
172 views

Error in command su

I am creating a command that will change a certain line in the /etc/profile file from a script, however in certain versions of Linux the sudo command may not be activated so it would be necessary to ...
Jean's user avatar
  • 17
2 votes
1 answer
66 views

Continue a directory tree checksum from a given file

I have: A checksum.txt file which contains many lines of checksums of single files from a mountpoint in a huge directory, which mounted and then it disconnected, thereby not finishing the checksum....
Sir Muffington's user avatar
1 vote
0 answers
30 views

Is it possible to write bash completion function when arguments are in the form --arg=argval

How to write bash completion when the arguments have no spaces but = For example myapp can take either --arg=argVal1 or --arg=argVal2 _myapp_completion() { local cur prev opts COMPREPLY=() ...
kanna's user avatar
  • 213
3 votes
1 answer
106 views

Will writing to /dev/pts allow me to source ~/.bashrc?

I have several terminal windows already open; I just made a change to ~/.bashrc, and I'd like to run source ~/.bashrc in each of the open terminals. It seems to me that if I just source ~/.bashrc | ...
Radoslav Ivanov's user avatar
2 votes
1 answer
75 views

How to run python script on login

I am attempting to load a python script that launches a Firefox Geckodriver under Selenium whenever a specific kiosk user logs in to the GUI. I've tried launching this via .profile, however ...
Firav's user avatar
  • 31
1 vote
1 answer
85 views

What does "/$" mean to "grep"?

I'm using these two codes below. ls -lap . | grep -v "/$" ls -lap . | grep -v "/" These two give me different outputs in some cases. What does $ mean in that context?
shersher's user avatar
2 votes
1 answer
85 views

Why does printing an array with @ using printf in bash only print the first element?

I have an array snapshots=(1 2 3 4) When I run printf "${snapshots[*]}\n" It prints as expected 1 2 3 4 But when I run printf "${snapshots[@]}\n" It just prints 1 without a ...
geckels1's user avatar
  • 153
7 votes
5 answers
2k views

How to execute a command on all files whose names match a pattern and whose contents match a pattern?

Say I want execute cmd on all *.cpp and *.hpp files that contain the word FOO. As far as just finding those files goes, I know I can do, find /path/to/dir -name '*.[hc]pp' -exec grep -l 'FOO' {} + ...
Enlico's user avatar
  • 1,666
0 votes
2 answers
63 views

How to find files with find tool in system path ($PATH)? Or alternatively, How to specify starting-point directory for find as an expression?

For example, I want to find all symlinks that reference to particular binary in all directories that belong to system $PATH. This can be successfully achieved with manual specification of all ...
Anton Samokat's user avatar
0 votes
0 answers
32 views

Difference between localectl and LANG environment variable

My default language was set to en_IN. Then I came across update-locale and localectl to change my locale to support UTF-8. I changed it using sudo localectl set-locale LANG=en_IN.UTF-8 However that ...
Abhisek's user avatar
  • 101
0 votes
1 answer
58 views

Running sudo, changing dir, staying in sudo, staying in dir after the script finished

I often find myself typing the following commands: sudo -i cd workdir I would like to create a script and name it a single letter. e.g. a so that when I run a the effect is identical to typing the ...
Andrew Savinykh's user avatar
11 votes
1 answer
738 views

Bash 4: unexpected EOF while looking for matching `)'

This very simplified version of my script #!/usr/bin/env bash example="$(bash -rs <<'BASH' -- 'This has been executed in restricted shell' echo "$1" BASH )" echo "$...
pedral's user avatar
  • 121
1 vote
2 answers
53 views

How to draw a red vertical line in center over image in terminal bash?

Sometimes, I need to make pixel-perfect HTML markup. This involves exporting a full-page JPG image of the page, importing it into GIMP, drawing a red vertical line in the center, exporting the image, ...
serii 's user avatar
  • 33
1 vote
1 answer
27 views

Moving and organizing files with find

I have a folder on a Debian GNU/Linux 12 (bookworm) x86_64 Server used as a NAS/Homelab server with a lot of files from a surveillance camera. MDAlarm_20240301-091804.jpg ... MDAlarm_20240316-153813....
JoSSte's user avatar
  • 195
4 votes
1 answer
1k views

Typing in the Terminal on Ubuntu takes seconds until the typed character appears

The problem: typing in the terminal on Ubuntu takes seconds until the typed character appears. I first noticed this after I moved large chunks of data onto another LUKS encrypted HDD which I mounted ...
VerteXVaaR's user avatar
-2 votes
2 answers
103 views

Tool(s) for echoing to a bash script only once if script is run more than once

Edit: It's unfortunate the downvotes. This isn't my problem. This is how Linux wants things done and the myriad of tools that have ad-hoc and inconsistent install scenarios. Me asking this question is ...
bmitc's user avatar
  • 97
7 votes
3 answers
1k views

How can I make a custom header in less? Or alternatively, how can I open two files simultaneously in less?

How can I prepend some custom text when opening a file in less? For example, I would like to see something like: My custom title Content of the opened file goes here... I want a command for that ...
Anton Samokat's user avatar
0 votes
1 answer
11 views

git diff tab completion of tags hides file name completion (using bash)

I am using git on Ubunto with bash shell, and a tab-completion using bind '"\t":menu-complete' in my .bashrc file. When I do git diff X, tab-completion starts cycling with matching git tags, ...
Itamar Katz's user avatar
0 votes
0 answers
25 views

Is it possible to take the output from ls and make each item a separate variable? [duplicate]

So, for complete transparency I am very new to bash scripting. I have taken on a personal project (to help my team at work) to make a script that backs up the data on our Mac devices and sends it to ...
TheBigDog's user avatar