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
Join us in building a kind, collaborative learning community via our updated Code of Conduct.

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
5 views

How to make an expect script to expect either of multiple texts

Below is a sample snippet, normally it works fine unless we passes some command which shutdown the server or cause a disconnection . To handle this, is it possible to expect either "#" or eof after ...
-3
votes
0answers
20 views

Second command won't run until the first has finished

I can't understand why this line won't work galculator & $(xdotool search --name galculator > file) the second command will only produce output if I launch it after the other from the same ...
2
votes
2answers
14 views

Stderr redirection unexpectedly redirects some BASH built-ins as well

I'm trying to hide all the stderr from users running an interactive BASH script but keep the errors in a log file. However, simple stderr redirection quite unexpectedly hides some BASH output as well ...
-2
votes
2answers
29 views

Shell scripting problem [on hold]

So I'm doing this exactly the way the tutorial tells me to, and something still doesn't work... 1 #!/bin/bash 2 users=$(ls *.usr) 3 date=$(date +%F) 4 for usr in $users 5 do 6 mv ${usr} ${date}-${...
0
votes
1answer
18 views

Echo a line of code to a file end up incomplete

While executing a script in bash echo "export PS1='\[\e[1;32m\][\u@\h \W]\$\[\e[0m\] '" >> /home/testusername/.bash_profile While I am reading the file is missing one character which is a "\" ...
0
votes
2answers
23 views

check command line arguments

I would like to check if the first command line argument ($1) has an minimum amount of 10 characters and if it is empty. The script is called as: ./myscript.sh 2018-08-14 I tried this but it doesn'...
2
votes
2answers
109 views

ls -d */ works in some folders and not in others

I'm on a remote server which is a Ubuntu 16.04.1 LTS and I need to list only directories in this folder called "NewsData" I found that ls -d */ is a good command to list folders, however it works in ...
0
votes
4answers
48 views

if negative or function in bash?

I'm checking a variable for a present string: check_string() { if [[ ! "$FILES" =~ "abcd" ]] || [[ ! "$FILES" =~ "xyz" ]]; then return 0 else return 1 fi } ...
1
vote
1answer
13 views

Not able to exit from interactive mode for yarn top command

I have a bash script which is on serverA. This script will ssh to serverB and runs yarn top command, pulls the metrics and put into the file(test.txt) on serverA. Below is the command which I am using:...
0
votes
0answers
21 views

How do I call current “.bash_history” from a script?

There is a program called "thefuck" that you can install and it uses python to take the last command you ran and give you ...what you probably meant. It's a cool program. I wanted to create a script ...
0
votes
1answer
26 views

Creating a global function on OS X

I'm very noob to bash, and so I'm sorry if this question is dumb. But I am hoping to add some basic global functions that I can use in any directory. Is this possible? Let's say I just wanted to do ...
0
votes
1answer
23 views

Bash the function is executed twice

The script has traps that execute a function that reruns the host script, but executes it twice. #!/bin/bash LOCK="/tmp/performanceScript.lock" exec_func () { #Creando Script de Vida Eterna. rm -f ...
0
votes
3answers
63 views

How to remove filename extension from a list of filenames in bash

I am trying to remove the filename extension from a list of files I've generated with the following bash script: #!/bin/bash file_list=$(find . -type f) #assuming that the files are stored in the ...
-3
votes
1answer
35 views

Changing a multiple file extension using single line command

I have some files whose names contain multiple extensions: $ ls -r File1_345.R.12345 File1_3.234.R.6789 File1_2345.R.2345 File1_12345.R.12345 $ I want to rename them to remove all the existing ...
1
vote
1answer
51 views

Iterate Through Array in Bash; Exit if No Matches are Found

In the following function, I can iterate through an array and, if a match is found, break out of the loop and continue with the rest of the program (as intended). I'd like, though, for the function ...
0
votes
0answers
13 views

Want to preserve bashrc and vimrc when switching to non-root users

I'm on a multi-user system. I have sudo b/c I'm responsible I guess. Sometimes, I want to switch to another user to help them do something, but I have a tricked-out bashrc/vimrc and I'd like to keep ...
0
votes
1answer
23 views

Rename Files to Consecutive Integers [duplicate]

I have bunch of files in one directory, like these: 0002.b3120c4bcbf3101e661161ee7efcb8bf 0003.acfc5ad94bbd27118a0d8685d18c89dd 0004.e8d5727378ddde5c3be181df593f1712 0005....
0
votes
1answer
35 views

In bash, why is `SHELL=/bin/sh lesspipe"` gramatically correct? [duplicate]

On Ubuntu-like linux, the default .bashrc file contains a line: [ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)" Then why is SHELL=/bin/sh lesspipe grammatically correct? What ...
0
votes
1answer
37 views

Loop to create subdirectories in multiple directories

I want to create subdirectories into each of directories below. I used the following loop: #! bash /# dir m3z m3t m3t2 m3g m3g2 m3g3 ... n dir for d in m3z m3t m3t2 m3g m3g2 m3g3 ... n ...
0
votes
2answers
31 views

re-write a string with text and numbers onto a newline and insert text

In Short, I want to split single line output string into multiple rows and label each raw with the hostname. Hostname ProcessName CPUCore output=$(ssh -q -o "StrictHostKeyChecking yes" $ssh_host '...
-1
votes
4answers
52 views

simple cat echo process substitution hangs

Simple process substitution with cat seems to hang: cat >( echo hello; ) never finishes. Also tried: cat >( echo hello; exit; ) Manually closing the standard out file descript from the ...
1
vote
3answers
85 views

run another process after the background process is complete

said i have looping script in file test.sh, i just want to running script "running_script2.sh" after the background process is complete, what i try like this, but it's not working . for id in 1 2 3 ...
0
votes
1answer
19 views

How to tunnel mqtt sub data to pure data (pd) in bash

mosquitto_sub -v -h 127.0.0.1 -p 1883 -t 'gyro' | sed 's/[^ ]* //' | pdsend 3000 localhost udp this command doesn't output anything. while it should output a value I receive over mqtt. without sed '...
14
votes
3answers
1k views

How do I find the line number in Bash when an error occured?

How do you find the line number in Bash where an error occurred? Example I create the following simple script with line numbers to explain what we need. The script will copy files from cp $file1 $...
1
vote
0answers
30 views

Bash completion overwrites current word

I am trying to create a bash completion script for my command. ls has the behaviour that I want. I need to get this same behaviour form my command. This is what I get for ls $ ls /home/tux/<Tab&...
2
votes
2answers
50 views

Using pipe STDOUT as a variable?

Fairly new to Bash, about a grueling week. I love it so far and really like long chaining pipes. What I'm noticing though is that I have to break the pipe if I need to use the STDOUT as a variable. ...
0
votes
1answer
110 views

Bash has performance trouble using argument lists?

Calling a function to do nothing f1(){ :; } is a thousand times slower than : but only if there are arguments in the parent calling function, Why? : #!/bin/bash TIMEFORMAT='%R' n=1000 m=20000 f1 (...
-2
votes
3answers
70 views

How to add more directiories in PATH [on hold]

Okay, first thing first, I'm new to Linux and I'm using Linux Mint. I learned that when I want to add more directories to my PATH (specifically my home directory) I need a Bash command that looks ...
2
votes
0answers
41 views

Dropdown menu in Bash

How can I make Bash show a typical Web-style dropdown menu when typing the argument to a custom-made command? (Making it work with builtins or Standard Unix commands is secondary.) The crucial parts ...
0
votes
2answers
28 views

python os.system: syntax error near unexpected token `(' - nested parentheses

I've read that I can put bash parentheses in quotes when submitting the command from python. In this case, I'm trying to create key and csr for openssl using a command that works on the shell, but ...
14
votes
3answers
718 views

What does `.[].foo[]` do in bash? Why does it match `..`?

Look at the following: $ echo .[].aliases[] .. $ echo .[].foo[] .. $ echo .[].[] .. $ echo .[].xyz[] .. $ echo .xyz[].xyz[] .xyz[].xyz[] $ echo .xyz[].[] .xyz[].[] Apparently this seems to be ...
0
votes
0answers
24 views

Daemonizing a bash script [duplicate]

I need a script to behave as as if executed by /.a.sh &, even though I leave out the &. Is there a more elegant way of doing this than wrapping the whole script in { .. } &?
1
vote
3answers
71 views

I need to find only directories in the directory but exclude a linked directory and its link

I am in a root directory and have some folders inside: 0.1 0.2 0.3 0.4 0.5 0.6 shortcut -> 0.6 I need to list the above directories without both shortcut as well as 0.6 folder. I don't won't to ...
1
vote
1answer
26 views

Copying files based on input list, special characters in file names

This is based on the question here. Problem: I have a .txt file listing file names I want to copy to the folder newfolder in the shell (Mac Terminal). Approach, where filelist.txt contains file ...
0
votes
2answers
15 views

How to pass in log file creation to pass in to script to attach the file

I have several cron jobs I run to back up dbs: 0 8 * * * BACKUP=DEV DB=01 /usr/local/bin/backup.sh > /var/log/backup-db01-`date "+\%m\%d\%y"`.log 2>&1||/usr/local/bin/create-ticket.sh 0 16 ...
1
vote
2answers
73 views

Bash: “bad interpreter: Too many levels of symbolic links” Error

Recently I made a bash executable file with permissions 722 as I am almost perpetually root. The contents of the file are as follows: #!/home/nolan/Documents/test/listFiles [ $# -lt 1 ] && ...
3
votes
2answers
44 views

Delete .pdf files only if .xlsx files in directory have same filename?

I have folders with hundreds of pdf and xls(x) files that were mass exported from legal e-discovery systems. The filenames in these exports correspond to bates # such as ABCD_00000001.pdf, ...
3
votes
1answer
27 views

Can I change a text file into a spreadsheet with grid lines, using a bash script?

I have the information below and I want it to look like it is in a spreadsheet with a header. cat TEXT-FILE.txt SOMETHING5 : 11111111 : 1969-08-12 : 42.34 SOMETHING4 : 22222222 : 1969-08-12 : 700.12 ...
0
votes
2answers
44 views

How to assign .* as a value to variable in bash [duplicate]

When I am assigning .* to a variable , it is assigning all hidden files. [root@s1 ~]# a=".*" [root@s1 ~]# echo $a . .. .bash_history .bash_logout .bash_profile .bashrc .cache .config .cshrc .history ....
2
votes
2answers
35 views

Run factor in parallel

how to run Linux's factor in parallel, i.e. utilize all CPU cores? I have tried to run factor <prime number> but unfortunately only one CPU core is being utilized.
0
votes
1answer
31 views

Script skipping a column

my script is supposed to go through each column from 1 to 13 but it ignores -f13. I changed it to -f14 just to see what it does and it printed out what I needed from -f13. Why does this happen? ...
0
votes
1answer
24 views

How do I output required entries from a CSV file into a new file and count the number of entries?

I have a CSV file of a table that has some entries that are blank. I want my code to look through all the entries for each row (except the first) and count the number of blank entries > store the ...
-2
votes
0answers
35 views

Using case statement in Shell Script and taking one input

can someone suggest, what wrong I am doing here? I am using 2 scripts, (one calling other). But it is not updating me with the correct result. Ist Script (init.sh): initUnixAccount_CRMBAP() { ...
0
votes
3answers
43 views

printing all directories and subdirectories function

I'm trying to print all subdirectories, using the function below but for some reason when the file name include spaces (" "), the echo splits the name into two parts. Here is an example: My directory ...
0
votes
1answer
14 views

Multi-line commands are messed up in my PS1

declare __host='\[\e[30;102m\] \h \[\e[0m\]'; declare __dir='\[\e[1;97;44m\] \w \[\e[22m\]'; declare __arrow='\[\e[1m\]▸ \[\e[0m\]'; function __git_status() { local info; info=$(__git_info) &&...
3
votes
1answer
59 views

How to delete one word forward in bash? [duplicate]

Delete one word backward: Ctrl + w Delete one word forward: ? Can anyone answer the above or do I need to add a command to stty as I can see by running the following command: stty -a that the ...
0
votes
1answer
27 views

Bash and Ksh background color - PS1

To change the back color my command is : PS1='\[\033[46m\]' This works fine for bash but in ksh it will but a [] in front of my server. Example : Bash : [USER@SERVER] (in color) Ksh : [][USER@...
1
vote
1answer
34 views

How to silently handle the “bash: /xyz: Is a directory” error in bash shell?

In zsh, executing the directory path will cd into it. I want to make bash shell to behave the same. The idea is to check and see if the error is bash: /xyz: Is a directory and cd into '/xyz' and ...
1
vote
1answer
33 views

Bash file: No such file or directory [duplicate]

I have the following script ssh user@host << EOF STATUS="$(git status)" SEARCH_STATUS="Not a git" if [[ "$STATUS" == *$SEARCH_STATUS* ]]; then echo "Not a git repository" ...
0
votes
0answers
19 views

Non-interactively change user in bash

I want to create a new user, add it to the sudo group and then change to that user not-interactively (i.e. without entering the password via stdin) in a test scenario on a vm. I tried this, but this ...