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
1answer
23 views

autoexpect script.exp

I use autoexpect generated a script.exp. see following. how to understand expect -exact " \r Type ha for help on aliases\r \r ]0;luoric@linux-pc-64:/home/luoric/tmp[01;34mluoric@linux-pc-64[01;34m ...
0
votes
1answer
36 views

What is the best way for storing and versioning his aliases/functions/symlinks?

actually I have these lines (exemplary) in my .zshrc file: . ${TOOLS_HOME}/cli/.cli_base . ${TOOLS_HOME}/cli/.cli_functions . ${TOOLS_HOME}/cli/.cli_symlinks This works fine so far. My only problem ...
0
votes
1answer
49 views

Linux “alias” command question [duplicate]

Where any aliased command is stored? If I am aliasing "ls" as "l" then where will that aliased be stored? Does it affect .bashrc or .cshrc?
1
vote
1answer
26 views

Outputting if the last command was a successful git checkout

I am trying to echo to the console in the event that a successful git checkout happened, but cannot get it to work. function prompt_command { prev=`fc -ln -1` ecode=$? if [ ecode = 0 ] ...
0
votes
1answer
40 views

remove only empty folders with empty flag - is it safe

we create the following command in order to remove only the empty folders that older then 100min find /tmp -type d -empty -mmin +100 -printf '%p was deleted!!\n' -delete because we intend to run it ...
1
vote
2answers
58 views

Find all empty directories AND directories with a single type of file

I'm trying to write a bash script that delete all empty directories as well as any directory that only container the .DS_Store file that Mac generates. I can do the former pretty easily with find -...
0
votes
1answer
54 views

Running a shell script with and without “bash” command [closed]

I have a script that runs fine when I add the "bash" in front of it, bash ./myscript.sh /opt/config/run.config but when I don't it stops at the below line and exits. source "/opt/config/test.config"...
1
vote
1answer
73 views

Match ASCII codes in shell regex

I've trouble about matching ASCII codes in regex in my bash script. My payload is : payload='#1243669, start 2018-12-17 16:32:50 CET' My old regex is : regold='(#[^,]+),' My new regex is : regnew='(#...
0
votes
2answers
33 views

Unable to print * (star) value with echo

I have, my.sh while IFS= read -r line ; do v1="$line"; t1=`echo $line | awk -F= '{print $2}'` echo "$t1" done < $1 sample.txt say=hello test=0 0/15 * * * ? logs=valuelogs Output : [root@...
0
votes
2answers
61 views

Problem with crontab

My script which starts a process and writes the PID of that process to file. This works as it's supposed to when I execute it from shell: process & echo $! > /home/xxx/PIDs/process.pid But ...
0
votes
2answers
75 views

how to replace file extension

we want to replace the script file extension so we did the following: new_name=` echo run_fix.bash | sed 's/[.].*$//' ` new_file_extension=".in_hold.txt" new_name=$new_name$new_file_extension ...
0
votes
1answer
58 views

How to know the name of the last command that was executed? [closed]

Let's say we run this script on Linux: /tmp/start.sh After running it, is there any way to retrieve the name of the last command executed? expected output start.sh
0
votes
0answers
14 views

Possible to trigger history append (and save to file) in an already running bash process remotely?

Let's say you have a bash terminal open, in which you have typed a lot of commands, many of which are probably not yet saved in $HISTFILE. Additionally, let's say that you have a long running command ...
1
vote
1answer
38 views

Shell: Is it possible to give a string as a file to a command?

Suppose we have a command, eval-some-language —-path=<filename> And we want to do something like this: eval-some-language —-path=“say hello world! exit 3” I think the following solution ...
0
votes
0answers
24 views

Is there a way to set coloring for “cd tab” complete on macOS?

I have turned on coloring, set colored-stats on in my ~/.inputrc but still not working, here is a screenshot, first one, cd tab & second is ls tab
0
votes
0answers
33 views

Script finding the total size of a directory and checking if a directory exists

I need one additional line for my script that finds the total size of a directory and shows it in bytes and another line in the beginning of this script that checks if a directory exists. That's my ...
0
votes
2answers
46 views

case insensitive, list files in directory, ending in .jpg [duplicate]

I'm trying to write an alias to list all the files in a directory ending in JP(E)G in its various forms. The ones I'm looking for it to recognise are .jpg .JPG .jpeg and .JPEG. Is there a form of ls (...
-5
votes
1answer
29 views

Script: Writing mailbox SQL record based on system users

There's something wrong with this command or I'm not seeing my mistake. I also needed to exclude disabled users and users with UID over 500. This is the SQL command I need to use INSERT INTO `mailbox`...
0
votes
1answer
52 views

Make bash-autocomplete recognize certain filetype for certain script

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

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

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 ...
8
votes
4answers
509 views

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

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....
8
votes
3answers
790 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
3answers
119 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" ...
0
votes
1answer
32 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 ...
11
votes
5answers
656 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
871 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
67 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
2answers
86 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 ...
-1
votes
0answers
40 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
47 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 ...
0
votes
0answers
80 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 ...
1
vote
2answers
45 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
23 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
149 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
2answers
39 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
1answer
42 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
350 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
47 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
21 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? [closed]

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 ...
-1
votes
2answers
39 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
28 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
24 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
50 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 "...
0
votes
1answer
32 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
vote
1answer
14 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
28 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 ...
0
votes
0answers
37 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
57 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
603 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 ...