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
0 answers
20 views

replacing part of find output in a readarray command

I need to create filelist (playlist) for using it in a Docker container. So the path of the file on the host system is not the mounting path. Now I try to fix this, but I have some trouble. This is my ...
user avatar
0 votes
1 answer
24 views

nohup: can't execute 'display_files.sh': No such file or directory

I want to run my code with nohup shellskriptname &. But whenever I try to see the nohup, it says there is no such file. What can I do, so I can enter it like that? #!/usr/bin/bash # To Display ...
user avatar
0 votes
3 answers
27 views

Split code in bash brace expansion

I have got stupid question about line break in bash while using brace expansion. For example, i have got something like this: echo {a,b,c,d} Now i want split code on several lines: echo {a,b, \ ...
user avatar
  • 3
3 votes
1 answer
238 views

Is it possible to pass a bash array by name as a parameter to a function? [duplicate]

I'd like to pass an array to a bash function but I get a bad substitution error Example mapfile -t ray < <(parallel -j 0 echo ::: {1..10}) declare -p ray declare -a ray=([0]="2" [1]=...
user avatar
  • 187
0 votes
1 answer
32 views

Grouping commands of if...then statement, including assignation of variable for shell/bash in a single line

I know the existence of while-do-done. Alternatively, I know that I can use for-do-done. But, I was trying to test manually using if-then-else. I would to like to execute a command, but doing a shift ...
user avatar
0 votes
2 answers
79 views

"cd" in a function works, except when it doesn't

The first thing I do after cd'ing to a directory is to use "ls", as I imagine is the case for a lot of people. So I decided to define a function in my .bashrc to do both together. This is ...
user avatar
-2 votes
0 answers
28 views

readline key bindings don't work properly in the default shell in Debian EC2 instance

I created a Debian EC2 instance. After I ssh into it, the default bash shell is strange to me. When I type in a command and want to edit the command before running it, moving left arrow key doesn't ...
user avatar
  • 91.6k
0 votes
0 answers
27 views

Bash Script to Recursively Rename Files without changing file extension

I am attempting to rename all files (.jpg,.jpeg,.mov,etc) in parent directory and all subdirectories to date_time_7digitnumber without changing the file extension. The below script accomplishes this ...
user avatar
9 votes
5 answers
2k views

Fastest way to merge millions of small files together

I regularly need to transfer millions of small files (small images, txt, json) with average of 5-50k per file between servers or to aws s3. Is there a faster to merge them into a single file to ...
user avatar
0 votes
1 answer
21 views

Use variable from file to push data through JSON

I'm currently stuck where I try to push data through API that requires JSON structure. I need to read value from file, where I wrote: file="/value" name=$(cat "$file") So $name is ...
user avatar
  • 141
3 votes
1 answer
80 views

How can I batch rename all files that match a pattern in Linux?

I have folder which contains many .mkv files that I'd like to rename without having to manually do so. The pattern is this: ... [XVC]_Control_-_10_-_Doctors_[SCB055Y].mkv [XVC]_Control_-_11_-...
user avatar
  • 1,099
3 votes
1 answer
350 views

mv: A and B are the same file

I'm trying to move 5 .MOV files to a folder called MOV. I'm using find to list the files and mv to move the files: $ mkdir MOV ; find . -type f -iname '*.MOV' -exec mv "{}" "MOV" \;...
user avatar
  • 135
1 vote
1 answer
27 views

How to do pattern matching on `.bashrc` for file extensions

I'm modifying my .bashrc: I want to make it so that .zip,.tar and .tar.gz files (and maybe more later down the road) are shown with a red color. Thing is, I want to match for all those files once. So ...
user avatar
0 votes
1 answer
19 views

MSYS2: Command works fine in terminal, but syntax error `(' in script

On Windows, with MSYS2, I want to add the file extension for an executable back to the output of which, if it has one. Here's a one-liner: locAlt="$(which "mingw32-make")" ; echo &...
user avatar
  • 101
0 votes
0 answers
41 views

open a file with a shell / bash script and get the filename

I want to create a script which handles specific files. It works so far with a simple open file dialog but I'd prefer the "open with" option where the file is opened with the script itself ...
user avatar
-1 votes
0 answers
16 views

Why bash in X not child of login from where startx was run? How to add user to a group w/out restarting whole OS with systemd?

I booted (Linux Mint 20.2 distro) in text mode. Added account to a group. groups did not list that group. Fine (I recall works after re-login). So I've exit and logged in. Yes, now groups listed new ...
user avatar
0 votes
1 answer
62 views

The letter "y" won't print in macOS Terminal

I'm learning BASH scripting, and I upgraded my BASH to version 5.1 using Homebrew. When I try typing "y", I just get a sound. When I run a script with a letter "y" in it, I get the ...
user avatar
  • 3
5 votes
0 answers
107 views

tee is faster than no tee

I have this simple bash script #!/bin/sh for i in {1..1000000} do echo "hello ${i}" done That prints a message a million times I try to compare the performance of dumping all the ...
user avatar
  • 151
1 vote
1 answer
13 views

Remove all words from string that match a pattern

I have a string like /usr/bin/gjs /usr/bin/com.github.johnfactotum.Foliate /media/ismail/SSDWorking/book-collection/_Books/_misc/100 Things.epub Here, I want to remove all words that containing /usr/...
user avatar
  • 1,600
2 votes
1 answer
44 views

Bash: install.sh: line 185: syntax error: unexpected end of file

I'm trying to build my own installer for my own Arch Linux distro based but i can't get this error off of me!!!! i know it can be a open if or while or do or something else but i can't find it!!!! And ...
user avatar
  • 77
0 votes
1 answer
42 views

How can I assign to a variable the result of conditional expression in a Bash script?

I am looking for an alternative to such javascript expression in bash: const a = (_expression1_) || (_expression2_); The example of bash code that does what I want in bash is: a=$(_expression1_) if [...
user avatar
2 votes
1 answer
28 views

notify-send with stderr in notification body if there is stderr

Suppose I have a command like: foo() { echo a echo b >&2 echo c echo d >&2 } I use the following command to process stdout in terminal but send error via notify-send foo ...
user avatar
  • 1,600
0 votes
0 answers
9 views

"Total In-/Out- coming connection awareness" - script?

once I had found a bash (or Perl maybe; it's so long ago, that I wasn't knowledgeable about bash enough to tell one set of hieroglyphs from another set so to speak) script that filtered the open files ...
user avatar
  • 313
1 vote
1 answer
27 views

Why does subshell background process not exit on parent process SIGINT?

I have the following script test.sh #!/bin/bash function cleanup() { echo "calling cleanup" echo "PIDs associated with $0" ps aux | grep $0 echo "killing $$ $(...
user avatar
  • 121
0 votes
1 answer
52 views

Why can't I single quote a variable?

So this snippet of code works just fine, the "$i" is in double quotes: for ((i=0; i <= 10; i++)); do printf '%d\n' "$i" done However, if I put the "$i" in ...
user avatar
0 votes
2 answers
27 views

Inline grouping commands in case statement not working: syntax error near unexpected token `;;'

In my bash script, I parse arguments. I want to try to allow only one argument to be without specific pattern, which would be the "path". Any other argument that doesn't fit the cases should ...
user avatar
0 votes
2 answers
78 views

Need help on shell script option processing

I am struggling to make a script have this behavior: I want to pass options like this ./script -ab is the same as ./script -a -b And have this logic: "a & b -> c", "a & c -&...
user avatar
2 votes
2 answers
47 views

Can getopts arguments be combined with other input?

I am writing a script that would take a string as input along with other options the user can select by using arguments as indicators. So in other words, something like this: ./script "My input ...
user avatar
1 vote
1 answer
25 views

Bash meta-history: recall bash history modification to prompt?

With !!:gs/foo/bar/ I can modify a previous bash command. Is there any way I can recall the history modification command to the prompt (rather than the result of the modification) in order to be ...
user avatar
  • 175
1 vote
1 answer
56 views

"ls" sees different files in the same folder on the same machine in two different terminals. How is this even possible?

A very strange situation occurred to me just now. I'm managing some stuff on a cloud VM running Ubuntu over SSH in a TMUX session. Right now, I have two panes open, which see different files even ...
user avatar
  • 231
0 votes
1 answer
59 views

How to compare hashes of files in bash script?

I am using sha256sum to check whether file has changed or not within the bash script. My idea is to first store the sha256sum in a *.sha256 file. Then if this is present then use this for sha256 ...
user avatar
0 votes
2 answers
45 views

Getting an error in the if condition

I am just checking whether the password contains a small and capital case letter, I am getting an error at line 19. myscript.sh: #!bin/sh read password conditionarr=(0 0) if [[ $password =~ [A-Z] ]] ...
user avatar
2 votes
1 answer
67 views

How to do smart backups of terminal history

Trying to implement smart backups of my zsh terminal history (~/.zsh_history). Same goes for bash no difference just the file is called .bash_history. So far I have decided to create a private git ...
user avatar
  • 21
0 votes
0 answers
41 views

x unbound variable

I am trying to run that script here: #!/bin/bash set -o errexit # be strong with errors set -o nounset # be strong with unset vars PROG="${0##/}" # Scriptname USAGE="usage: $PROG ...
user avatar
2 votes
0 answers
19 views

bash tab-completion: complete full path on single tab in git commands?

Whenever I tab-complete a file path after a git command in bash, e.g. git add, I have to press <TAB> multiple times to complete to the actual filename, depending on how many subfolders there are ...
user avatar
0 votes
2 answers
21 views

No new line when piping into xclip

Is there something I can do so that whenever I pipe something into xclip it does not include a new line at the end? As a workaround, I am using echo -n $(CMD_TO_COPY) | xclip, but it's kind of ...
user avatar
0 votes
0 answers
18 views

Slow mounting cifs-share

I wrote this simple script to save my daily screen-/worktime. #!/usr/bin/env bash # Make this as an alias for reboot & poweroff, # so the complete uptime per day is logged log="$HOME/.local/...
user avatar
  • 43
0 votes
1 answer
16 views

Passing jsonfile content as request to cURL [duplicate]

I have a bunch of json files that I need to use to test a docker container. From postman I extracted the code to use and it looks something like this: curl --location --request POST '<adress>' \ ...
user avatar
1 vote
1 answer
22 views

Podman Ps Format help

I am trying to list podman ps in a very readable format using podman ps -a --format="ID\t{{.ID}}\nNAME\t{{.Names}}\nIMAGE\t{{.Image}}\nPORTS\t{{.Ports}}\nCOMMAND\t{{.Command}}\nCREATED\t{{....
user avatar
0 votes
0 answers
21 views

Can I point cursor to a character on bash CLI prompt using mouse?

How can I point my cursor to a character on bash CLI prompt using mouse? Example: user@host:$ grep abcd /tmp/dir1/dir2/dir3/ *.c | grep st1 In this example the command is lengthy and if I want to ...
user avatar
  • 157
0 votes
1 answer
29 views

Creating a secure transcient duplicate of a folder for consumption by ‘psql’ running as ‘postgres’

This is a question about finding an ideal way to deal with a particular situation. In a folder under my home folder is a group of psql script files that reference each others through \include_relative ...
user avatar
  • 137
0 votes
0 answers
33 views

How to know if `script` command (which recordings terminal sessions as typescript) is already runing?

This SO answer says that script adds the variable SCRIPT to the environment of the command it runs. I tried that but it doesn't seem to be working now. This is what I have tried ma08@IWeighHar:~/pro$ ...
user avatar
  • 805
-3 votes
3 answers
77 views

linux find command + delete all snapshot files except last 5 ordered by date

under /zookeeper/version-2 , we have many zookeeper snapshot files . . . -rw-r--r-- 1 zookeeper hadoop 495333240 Aug 3 14:51 snapshot.5d00011991 -rw-r--r-- 1 zookeeper hadoop 495333240 Aug 3 14:53 ...
user avatar
  • 11.3k
0 votes
1 answer
18 views

Rename files and folders recursively depth first

From another answer on this site I've gleaned the following snippet for renaming files recursively: find . -iname "*oldName*" -exec rename oldName newName '{}' \; This works great if you're ...
user avatar
5 votes
4 answers
543 views

Copy file to same path as source without changing directories [duplicate]

Suppose I have a path like this under some directory (e.g. home): ~/mydir/subdir/file1,and I want to make a copy of file1: We could do this from the home directory: cp ~/mydir/subdir/file1 ~/mydir/...
user avatar
  • 395
-1 votes
2 answers
41 views

Use Git Version of mv/rm etc When in Repository

Git has its own versions of commands such as mv and rm that we really ought to use when doing these operations inside repositories. However, I'm sure I'm not the only person who often forgets to do ...
user avatar
0 votes
1 answer
15 views

How to determine the active systemd-resolved link number using a script?

Because several of the resolvectl commands take the link number as an argument, how do you determine which of the links is the active (current) one? So far I have: $ resolvectl status | grep -PB1 '...
user avatar
0 votes
1 answer
36 views

Append files output dynamically

I'm trying to append the contents of several files into a single combined one. Right now I'm doing it like this: cat file1 >> file2 >> file3 >> combined It is working fine, but the ...
user avatar
  • 1
0 votes
0 answers
30 views

How can I obtain a full tabular list of the running process on my system (with their command name and PID at least) for text processing consumption?

When I run top I see a screen similar to this, PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 654 root 20 0 25.5g 147780 70084 S 3.7 0.9 72:08.69 ...
user avatar
  • 1,044
1 vote
1 answer
11 views

How to include all scripts of a directory into the current shell session?

I have a directory that contains some script files: /scripts api.sh time.sh certificate.sh docker.sh nginx.sh wifi.sh ... These scripts are not commands. They just contain ...
user avatar

1
2 3 4 5
478