Questions about bash only, as opposed to other Bourne/POSIX shells. For all Bourne/POSIX-style shells, use the /shell tag instead.

learn more… | top users | synonyms

0
votes
1answer
14 views

Scope of shopt options in cron script

I have a bash script that is run nightly in a cron job. It needs to do case insensitive file matching, so the script calls shopt -s nocaseglob I want to make sure this does not affect other cron ...
2
votes
1answer
47 views

Bash Array Comparision

Within a bash script, I am building two dynamic arrays. And I want to construct another array with difference of two. Example: array1=("aa-1234|safsf|sfsfs" "aa-2345|sfsfs|n0sfm" ...
2
votes
3answers
212 views

Bash File existence test is always true

I have the following lines of bash script to test whether a file exists: MYAPPPATH=$(find $APPDIR -iname myapp* -print) if [ -e $MYAPPPATH ] then echo "File exists" fi However when file ...
3
votes
2answers
31 views

How to print a range of IP addresses with Linux seq command

How can I print a range of ip addresses on linux command line using the "seq" command? For eg: I need seq to print a range of ip from 10.0.0.1 to 10.0.0.23 . Seems like the period in between the ...
5
votes
3answers
539 views

Shorter command for deleting files

Our web server was originally maintained by a different company. They wrote a short script to clean out cache files. Their file has several lines that read like this: /usr/bin/find ...
3
votes
0answers
79 views

Bash Script - Wget Graphical Download Progress

I'm trying to port this code from wget + zenity to wget + kdialog. The code with zenity: #!/bin/bash # Start wget | zenity # Note the & at the end of the pipe, this allows the script to continue ...
3
votes
3answers
106 views

Why is my script calling multiple functions? [duplicate]

I am new to writing scripts in bash. My script is simple, I have a few sets of scripts that I've written to make setting up linux very simple. So I have made those scripts into separate functions ...
0
votes
1answer
11 views

How to script with systemd-cgtop?

The manpage for systemd-cgtop says that if there is no attached tty it will do one iteration and then print it out, saying that this would be useful in scripts. However when I try to do this from a ...
1
vote
1answer
28 views

bash completion: how to complete a list of hosts for a specific argument?

My programm can have the following format: <command_name> <arguments> <options> -hosts <host1> <host2> ... <hostn> (<more_arguments>) ... I am trying to set ...
2
votes
2answers
58 views

Inputting user input automatically through bash script? [duplicate]

I am creating a bash script which creates a user and sets a password. When the command "passwd user" is run it requires the user to enter a password and stops my script. Is there any way to fulfill ...
1
vote
3answers
41 views

making 4 out of 1 file with awk

i have large list - text file with 1 column of numbers (length=14). Numbers have 4 difrent prefixes 00001-00004. how do i split 1 list to 4 diffrend files. 1 file shoud contain list of numbers with ...
0
votes
0answers
13 views

Need explanation on an if statement with non understood condition [duplicate]

I came across this if statement which escapes to my understanding. Could anyone explain it to me? if [ "${-#*i}" != "$-" ]; then......
2
votes
2answers
45 views

Bash extended globbing

I'm unable to show JUST ONE file from the output of ls using bash extended globbing. From info bash If the `extglob' shell option is enabled using the `shopt' builtin, several extended pattern ...
1
vote
1answer
46 views

Concurrency problems with GNU parallel

My scripts are having trouble with correctly running things in GNU parallel. I have a sub_script like so (all these are actually simplified versions): #! /bin/bash input=$1 # input is a date in ...
1
vote
2answers
45 views

Save AWK FNR as a Bash variable to continue search from the line

I'm trying to get to run this on a sorted file. This returns the last line which is less than or equal to the given value comparing the first 9 characters. This would be done multiple times and VALUE ...
1
vote
2answers
34 views

Store stdout in variable and send command to background

I have a command in a bash script which I want to capture the output of and then send it to the background. How do I get this done? The following doesn't seem to work (it keeps blocking and outputs ...
1
vote
3answers
61 views

Generate networking configuration files using sed and bash

I am a bit rusty on my scripting abilities and am trying to find a good starting point for creating a script that creates files (generating new file names) and edits the IP address in the file by ...
5
votes
3answers
272 views

How to iterate a zero padded integer in bash?

How does one iterate a string with the form "[A-Z][0-9]*" Or for example: "A000001"? After receiving the variable I split: current_=$(mysql -h"$mysqlhost" -u"$mysqluser" -p"$PASS" "$DBNAME" -se ...
-3
votes
0answers
73 views

Drawbacks of UNIX [closed]

I have been hearing a lot about the advantages of linux and other *NIX. These Range from developer productivity, Free software (in case of GNU/Linux)to high stability and security and so on. I believe ...
1
vote
2answers
48 views

syntax error in conditional expression

I am writing a script where I am using the combination of logical 'OR' and logical 'AND' statement. This is the script: #!/bin/bash echo "Enter the value of a" read $a echo "Enter the value of b" ...
1
vote
1answer
21 views

Removing mulitple extensions in chrome

I need to remove multiple chrome extensions from several hundred devices. I have a script that will see if a certain extension exists and if it does then deletes the Default folder. How can I add ...
2
votes
2answers
63 views

syntax error near unexpected token `<'

I am writing a script to read the output of a command to variable a and b. This is the script #!/bin/bash read a b < <(awk '/Application Server/ && !seen[$7]++{printf "%s ", $7}' ...
2
votes
1answer
26 views

Problems with find, xargs and egrep

I this is what I what I'm trying to end up with (except working) find ./ -mindepth 1 -type f -mtime +60 -print0 | xargs -0 egrep -vZ 'vvv|iii' What am I doing wrong? $ ll total 0 -rw-rw-r-- 1 ...
5
votes
3answers
54 views

Is there an easy way to change directories from within one duplicate folder structure to another?

On our server, we have several duplicate-ish folder structures for testing, staging, and production. Other than minor changes, the folder structure between all three are generally the same. When I'm ...
2
votes
1answer
31 views

How can I add four spaces before each lines of programs code in terminal

I usually go to stackexchange when I face programming terminal and I spend most of time trying to append four spaces before my pasted programming code. Is there any faster way to do it from a ...
2
votes
3answers
50 views

How to open terminal, split to 9 terminals and switch between them using one script?

I would like to open a terminal, split it to lets say 9 parts (3x3) and execute some bash script. But for each terminal part different script. Can this be done using perl, python or even bash? How ...
0
votes
2answers
45 views

How to list files and directories of a mount point

Given a mountpoint such as /dev/sda1 how can I list the contents of this file system using shell script. My objective is to delete the oldest file in this drive.
2
votes
3answers
62 views

How to sort filenames with spaces in them and concatenate the files?

I have the misfortune of dealing with filenames that contain spaces. I want to concatenate files of which filenames contain spaces. I also want to sort the filenames numerically. Obviously the ...
0
votes
4answers
80 views

Can you put an if statement within an until loop?

We have to make a script with one until loop to repeatedly ask the user for a number. - If the number is not 50, display the message, “Wrong number; try again.” - ask for another number. - If the ...
0
votes
2answers
23 views

Number of occurences of letters in a word?

I would like to find out the number of occurrences of each of the alphabets in a word. Eg input aabbbddd output a@2 b@3 c@0 d@3 How can I perform this using shell script?
2
votes
2answers
195 views

Different MD5Sum for the same file in same directory

I find it odd as I managed to get different md5sum using the exact same file from the same directory. The output as below: [root@testlabs Config]# ls Backup_Files hostname1-config.uac ...
1
vote
1answer
37 views

Rename bash script - false no such file or directory error

I am trying to rename a few hundred files based on another file in the same directory. I found a script and with modification I have the following: while read file; do echo mv ...
6
votes
1answer
136 views

Conditional grep without quiet option

I always thought the quiet (-q) option had to be used when using grep conditionally. But re-reading the man page it seems like it should work without it. So if you want to print matches and use it in ...
3
votes
2answers
70 views

Execute code on remote machine and copy the results back

I'm using some old Fortran code that uses some peculiar memory handling. To make the long story short, it runs on my local machine but fails on the remote one. This is why I would like to ssh to my ...
2
votes
1answer
41 views

Help understanding the bash code? [closed]

What does this code do? export user=$(who am i | sed -e 's/ .*//') echo $user egrep -i "^www-data" /etc/group >/dev/null 2>/dev/null if [ $? -eq 0 ]; then group='www-data' else ...
2
votes
2answers
116 views

Left and right square brackets treated differently by sed/bash

I have a file with the following contents: [root@server list]# cat filenames.txt [AAA','ACMEDEMO2','ACMEDEMO3','ACMEDEMO4','RENTCOGH','TESTENT','DORASINE','LOKAWINK','BBB] [root@qa4app01 list]# I ...
4
votes
1answer
40 views

Are there problems with hyphens in functions, aliases, and executables?

In my testing (in Bash and Z Shell), I saw no problems with defining functions or aliases or executable shell scripts which have hyphens in the name, but I'm not confident that this will be okay in ...
4
votes
3answers
148 views

Change case of n-th letter in a string

I want to change the case of the n-th letter of a string in BASH (or any other *nix tools, e.g. sed, awk, tr, etc). I know that you can change the case a whole string using: ${str,,} # to lowercase ...
1
vote
1answer
25 views

Bash command to determine which string in a group of strings is a prefix of another string

Here's what I'm trying to do: I have a folder for code repositories, and I'm looking for a bash command that can tell the "code root directory" of the current working directory. For example, if I'm ...
3
votes
3answers
91 views

Why does my grep expression need to use $'string' to match tab characters?

If you take this code: echo -e '\t\t\tString' | grep '^[\t]*String' the result is blank because it doesn't match, yet this: echo -e '\t\t\tString' | grep $'^[\t]*String' works. I swear that I ...
11
votes
3answers
278 views

Get all possible combinations of a word in lower/uppercase letters

I want to write a bash script to print all possible lower and upper case permutations of a certain word, e.g. harley: harley harleY harlEy harLey ... HARLey HARLEy HARLEY My naive solution is to ...
1
vote
3answers
74 views

What return/exit values can I use in bash functions/scripts?

I want to know what return values we can use that will not be mistaken by for ex. SIGINT? ex.: $sleep 10 $#hit ctrl+c $echo $? 130 so I know I must not use anything like return 130 or exit 130 so ...
1
vote
3answers
47 views

How to remove matching files from directory A in directory B in the command line?

I have some duplicate files in directories A and B, how could I delete the dupes in B using the filenames from A in bash? How to do it in other shell's is a welcome bonus.
1
vote
0answers
32 views

How to force bash to start at index 0 with select output?

Well, even some less-experienced bash users would know meanwhile about the fact that bash arrays would always start with index 0. However, select will always do its own thing, as the following example ...
3
votes
4answers
124 views

Get pairs of lines and multiply [closed]

I'm trying to parse an html file for some values using bash. So I've got a big text file with numbers like this 3 2 4 2 What I want to do is get two lines, multiply both numbers and then store the ...
0
votes
0answers
58 views

Strange bash sytax error depending on sudo usage

I made this bash function to detect if the user running is actually logged in as root user and not using sudo by checking the uid + home directory of the user executing the command: #!/bin/bash set ...
0
votes
1answer
24 views

regexp in find to locate only

I have csv file (products.csv) with product numbers $ cat products.csv | head -3 2.20 2.21 2.22 in another directory I have thousands of product images in subdirectories. I need to locate product ...
1
vote
1answer
50 views

How do I define alias with variables which can be changed at runtime?

This is probably a very easy to answer question, but I could not find any questions already asking this due to different wording when writing titles. Running help alias on my bash prompt returns only ...
4
votes
2answers
96 views

Why does my Python background process end when SSH session is terminated?

I have a bash script that starts up a python3 script (let's call it startup.sh), with the key line nohup python3 -u <script> &. When I ssh in directly and call this script, the python ...
3
votes
2answers
144 views

Bash - echo line by line, ignoring the space between the lines

I had read the post on: bash - replace space with new line, but it does not helped to solve my issue. [My Directory] [root@testlabs Config]# ls Archive Backup_Files config_file.tgz ...