Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

0
votes
0answers
10 views

Can changing .profile of some user be done with Ansible?

Because I always like to work in full debugging mode interactively, each time I create a new Linux system I Add the following code to the very end of the .profile file of my main user (with this cat ...
0
votes
1answer
22 views

Make bash-autocomplete recognize certain filetype for certain script

How can I make bash recognize a certain filetype for this specific script? for example, I wrote a tiny script to compile a lilypond-file and then automatically open the compiled pdf: #!/bin/bash ...
1
vote
1answer
23 views

Can't change shell from dash to bash on Linux Mint VM

Just installed a virtual machine via virtualbox yesterday and I'm having trouble switching the shell from dash to bash. I've tried chsh as well as modifying the file directly, but it still defaults to ...
4
votes
2answers
169 views

When running a command on a file, is there any way to reference the file without typing the entire name?

For example: tar xvf test.tar.gz ; rm test.tar.gz Is there a faster way to reference the file name on the second execution? I was thinking something like this (which is invalid): tar xvf test.tar....
7
votes
2answers
170 views

How to print strings separated by TAB in bash?

I am trying to print two string separated by a TAB. I have tried: echo -e 'foo\tbar' printf '%s\t%s\n' foo bar Both of them print: foo bar Where the whitespace between the two is actually 5 ...
3
votes
1answer
53 views

How can I split a string to letters with IFS and read at no space/null, space and at a character -?

I have a string -w o rd. I need to split it to w o r d or to an array for 'w' 'o' 'r' 'd' it doesn't really matter. I have tried the following IFS='\0- ' read -a string <<< "-w o rd" ...
-10
votes
0answers
43 views

CSV bash parsing [on hold]

ive been trying to get a script working to create multiple users from a .csv file in bash. My .csv file is separated by ";". here is an exemple: username;password;fullName;PrimaryGroup;...
0
votes
1answer
30 views

Starting multiple independent processes

I'm trying to start multiple processes at the same time using a for loop. I want each to be created in it's own console window. So far i have the following: for i in {1..5}; do konsole -e "./program ...
-1
votes
0answers
24 views

i got errors when installing dalto release 2018 , please help [on hold]

I’m trying to install dalton-release-2018, but I got these errors: /home/kader/dalton-release-2018/DALTON/qfitlib/qfitlib_interface.F90:31:31: use qfit_input_readers, only: dalton_input ...
11
votes
5answers
605 views

How to plan a task to run after another already running task in bash? [duplicate]

I'm looking for something like command1 ; command2 i.e. how to run command2 after command1 but I'd like to plan execution of command2 when command1 is already running. It can be solved by just typing ...
3
votes
2answers
769 views

How do I make a while loop with multiple conditions stop at a true condition?

I am supplying a while loop with the following #!/bin/bash number1=1 while [ -z "$number2" ] | [ "$number2" == 404 ] & [ "$number2" != 200 ] & [ "$number1" -lt 13 ]; do #number2=$(some ...
0
votes
1answer
49 views

Is there a totally empty Bash file I can use (or create) to extend .bashrc and .profile?

I know that by principle, one shouldn't change .bashrc and common changes like creating an alias should better be done in .profile instead. When I rent a new IaaS system with Bash as main shell, the ...
1
vote
1answer
47 views

Script for checking if device is online, if not then do something

I'm building an IP Camera Server for rtsp ffmpeg capture and 24/7 purposes. Only thing that is missing is a script that checks connectivity of the camera and if it's not reachable there should be ...
0
votes
0answers
37 views

Why my other Bash instances died when I killed only one

so take this as an example: $ docker run -it --rm ubuntu root@7ca4573c1a7a:/# bash root@7ca4573c1a7a:/# bash root@7ca4573c1a7a:/# ps axuf USER PID %CPU %MEM VSZ RSS TTY STAT START ...
1
vote
1answer
45 views

bash script not working properly

I just started to learn some basic bash scripting and fail to reproduce the simples of scripts. I have got the following script: #!/bin/bash for file in "/home/test/*"; do echo test done This ...
1
vote
1answer
43 views

Bash completion comes back from the dead

I started with this problem: Bash disables autocompletion for some commands The only difference was that in my case the command in question was configure. I successfully applied the solution ...
0
votes
0answers
18 views

Cygwin rsync backgroud job [on hold]

We are moving windows server from a very old version (2008) to a new one. We are putting the storage on a nfs system that will be shared between several servers. All good and well - but the 2008 ...
1
vote
2answers
39 views

Do we need to define the shell on file that include only functions?

I am wondering if we need to add shell title: #!/bin/bash on a script, second.sh, which only defines a function, and is called from another script, script.sh. For example, with script.sh containing ...
0
votes
1answer
22 views

Shellscript `grep` execution not working as in the interactive shell

Having to deal with an environment where ack and so on is not available nor installable, this command try to limit only relevant files to find string through the C++ project : grep pattern --color --...
0
votes
4answers
111 views

Temporarily declare a variable in Bash

To declare a variable in Bash, say in a Bash script-file (that doesn't include Bash function), I do for example x=y and when I finish using it inside that script-file I do unset x. Is there a way (...
0
votes
1answer
40 views

Cannot mkdir -p with variable representing relative directory path in bash script [on hold]

I open command terminal and change directory to Desktop cd ~/Desktop/ I create file call myScript.sh touch myScript.sh I open myScript.sh with vim and add code #!/bin/bash mkdir -p ~/Desktop/a/b/...
0
votes
2answers
34 views

Unix Script, problem with a 2d array

I have 2 arrays that refer to files for example alpha=file 1 beta=file2 Charlie=file3 delta=file4 beta2=file5 beta3=file6 Charlie2=file7 charlie3=file8 delta2=file9 delta3=file10 array1=("$alpha" "$...
0
votes
0answers
44 views

visualizing shell scripting spaghetti [on hold]

I've inherited a system of shell scripts (40 in total) which maintain a website. Each script is under 1000 bytes and they are spread across multiple nested subdirectories. I'm trying to understand ...
0
votes
1answer
35 views

Basic progress bar for each line of output in an async bash script

Say I have this basic bash script for installing Vim plugins: #!/usr/bin/env bash plugins=( tpope/vim-endwise tpope/vim-fugitive tpope/vim-surround tpope/vim-unimpaired ) rm -rf $HOME/.vim/pack/...
3
votes
1answer
323 views

getopts does not seem to work

I am trying to run the following script using getopts to parse the options but it does not seem to work: #!/bin/bash set -x echo $@ while getopts "rf" opt do case "${opt}" in r) ropt=${...
0
votes
1answer
38 views

Nested double quotes for wrapping variables

There is one line in my bash script file like this: echo "$string" | sed -e "s|\($str\)|$(wrap \\1 $1 $2)|" Now, I want to wrap the $1 and $2 with double quotes for preventing errors while $1 equals ...
0
votes
1answer
20 views

bash string increase from vda to vdb in a loop

I would like to increase a string by one, for example, from vda to vdb, from vdb to vdc and so on. I was able to do it in one of the languages in the past by doing something like: $c="vdb"+1 and c ...
0
votes
1answer
22 views

Why does read from variable give blank new variable? [on hold]

I am trying to get a folder name from a stored variable string. When I ran the following path="Folder%20Name/Dir/File" read -d "/" folder < <(echo ${path/\%20/ }) echo "$folder" I am getting a ...
-2
votes
2answers
29 views

Replace a variable with stdin?

I want to loop over some values and I know I can simply use a for loop but is there any other way that I can replace a variable value in a command at the end of the command? Somewhat like echo 11"$...
0
votes
1answer
24 views

Handle filenames containing whitespaces passed to Bash function using wildcard [duplicate]

How is it possible to make a Bash function handle properly filenames containing a whitespace when filenames are passed using wildcard? $ touch a "a b" b $ ls -1 * a a b b $ function foo { ls -1 $*; }...
0
votes
1answer
19 views

What do I need to do to get qrandom to pipe data correctly into a running script without it throwing errors?

Recently, I have failed to input data from qrandom with a script. The pipe script is down below. while true do echo 1 echo $((qrandom --int --max 69 --min 1)) echo 2 echo $((qrandom --...
1
vote
2answers
48 views

Linux - case command

How to have spaces or tabs in the menu list? PS3='Please enter your choice: ' options=("Option 1" "Option 2" "Quit") select opt in "${options[@]}" do case $opt in "...
-2
votes
0answers
25 views

BASH Creating a unique username [on hold]

I originally posted the question here... Unfortunately, there is no way for me to reply to answers, so I made this one. Feel free moderators to delete the original post. I have a textfile called "...
0
votes
1answer
30 views

<<EOF specify a variable

I use a command in bash such as: gmx_d energy -f ener.edr -o outfile.xvg <<EOF 1 2 3 4 5 EOF to print in file outfile.xvg 5 different properties. Is there any way to add a variable such as ...
-1
votes
2answers
40 views

BASH Creating unique username [on hold]

I want to create a unique username based on the following bash script. The variable "user" should change based on the following criteria below. How would you achieve this? tput cup 18 18 echo "...
0
votes
1answer
11 views

Export ArangoDB values to bash script

I have a bash script that needs the count of records/documents that exist for a given arango collection. This seemed easy enough, I used the following arangosh call: records=$(docker exec -it arango ...
0
votes
1answer
25 views

How can I extract a function from bash/zsh with all its shell-related dependencies?

I write a lot of little useful functions, and sometimes I like to share them with friends or the world. The problem is that I use a lot of my helper functions and aliases in my functions, and I don't ...
-1
votes
0answers
25 views

Bash grep with date comparison

So, I have basically automated a majority of client license expiration reports and license renewals for our clients (I grep files for 31-dec-2018 and then echo the information into a text file that ...
0
votes
1answer
34 views

dollar sign inside eval string in bash

I have hundreds of sub-directories which contain a dollar sign (i.e., $) as the 1st character in their names, each of which needs to be visited. These sub-directories can not be renamed. The bash ...
7
votes
4answers
544 views

Viewing man pages in vim

I wrote a function in bash to see manpages in vim viman () { man "$@" | vim -R +":set ft=man" - ; } This works fine, the only problem occurs if I pass a manpage to it which doesn't exist. It prints ...
0
votes
1answer
66 views

bash: Boolean math and unary '!'

I came across this code that echo true if the year is leap, false otherwise. year is the user input that I read in from command line. (( !(year % 4) && year % 100 || !(year % 400) )) &&...
0
votes
2answers
32 views

why we get values in variable that are different

when I want to get the size of sdb size on remote machine - master I get that: # ssh master "lsblk | grep \"^sdb\" | awk '{print \$4}' " 100G but when we want to set the size value in variable ...
0
votes
3answers
38 views

split variable into multiple variables in loop

i am searching on these forums and trying different codes, but i cant seem to get it working: i have a variable ip="192.168.1.227 192.168.1.205 192.168.1.217" no i want to split every ip address up ...
0
votes
1answer
23 views

read issues with ls -i

If I write: ls -i '/home/user/Desktop/file' | awk '{print $1}' I get the inode number of the specified file. I want to make a script that gives me back the inode number of a certain file. If I do: ...
0
votes
3answers
40 views

case with a $@ variable inside

I want the following script to allow the user to select --header and then insert file* as the file name to add a header to all valid files. #!/bin/bash case "$1" in --header ) for filename in "$@" ...
-2
votes
4answers
30 views

Attempting to get this program to only print Usernames that are between 5 and 10 characters long [on hold]

I have written a bash program that scans through /etc/passwd and prints out all of the usernames that are in the directory however i need the program to only print out usernames that are between 5 and ...
4
votes
2answers
57 views

How to run multiple processes and exit if any of them exits or fails

I am running multiple processes and want to exit with the appropriate exit code (this means error on failure, success otherwise) if any of them fails or exists. Additionally if any child process ...
7
votes
2answers
745 views

Required Bash Code for Hide Password during Typing [duplicate]

How can I write Bash Code for Hiding Password Or convert into '*' user input will be in string so no spaces, and change or hide password String.
0
votes
2answers
23 views

Git: autocomplete my prompt after failed push because missing -u flag

Using git, I often create local branches and then want to push them to the remote (e.g. Github). This requires the -u or --set-upstream flag. Here is what git outputs without this flag: $ git ...
0
votes
4answers
39 views

How may I echo all parameters with greater than 2 characters in bash?

I have the following #!/bin/bash function f1 () { echo "all parameters with more than 2 characters" } f1 123 45 6789 I need to do something with parameters that have characters that are greater ...