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

2
votes
1answer
18 views

How do I run two processes and find out when one ends in bash

I was thinking to do something like this: command1 & command2 wait Will this work? I want to proceed when command2 finishes, but command1 can still be running.
1
vote
1answer
17 views

How can I detect that not enough options were passed with getopts

I want to add a line of code that tells the user that enough arguments were not given (may be an error message somewhere. but i am not sure where?) blastfile= comparefile= referencegenome= ...
-4
votes
0answers
34 views

Bash scripting: I am moving one hour old log files from host to rackspace cloud storage [on hold]

I am working on the cloud, using turbolifter to move one hour old log files from my server to rackspace cloud storage but it is not working due to a python issue. Therefore I'm using this script, but ...
1
vote
1answer
15 views

Write output from netcat to a file

I'm currently trying to write a scan port result to a text file Here is the command I tried to use: nc -vv -z localhost 1-80 > file.txt This doesn't work (that is, the error messages from nc ...
2
votes
3answers
131 views

Double square brackets for FreeBSD

I have this code: [[ "$1" =~ [/\\]$ ]] On linux it works just fine, but when I tested it on FreeBSD an error occured : ./projekt2.sh: [[: not found and it .. I there any alternative which would ...
2
votes
3answers
76 views

How can I create new shell commands?

I'm using bash, and I want to be able to execute a script just by typing its name as a command, same as pwd for example. Is there a specific directory where I need to save my script to, or any other ...
0
votes
1answer
32 views

Syntax Error: unexpected end of file — Bash script [on hold]

I am trying to create an spritz app. Everything was working fine, but since yesterday I keep getting this error: ./spritz: line 176: syntax error: unexpected end of file I have checked the script ...
-1
votes
2answers
16 views

Create new file with spaces from argument BASH [duplicate]

I need to create new file which contains spaces in it. And it is passed through the argument. This code below creates 2 sepate files. Can anyone help me how to create 1 file which will contains space? ...
2
votes
0answers
12 views

Catch/diagnose user process being killed - Inexplicably logged out automatically

Context: I'm using bash in Mac OSX Yosemite. Problem: I'm executing a (python) script that I expect to use alot of resources and take a few hours to run, redirecting stdout and stderr to a log file. ...
1
vote
2answers
30 views

How to set Timeout for an ssh command and also get back the result of remote commands

I have a script that runs on bash, in an RHEL server that connects to thousands of nodes and returns with the values of some 5 executed commands - It collects info from RHEL Servers only. It works ...
4
votes
2answers
172 views

Convert all first character in an email id to Upper case in BASH

I need to accept an email id and Full name in a script, and in case the Full name is not provided, I need to generate the name from the email id. Something like this: Case 1: EmailID: ...
0
votes
1answer
27 views

how to count the length of an array defined in bash?

I'm new to bash and can't find a good tutorial to answer my question. array=( item1 item2 item3) for name in ${array[@]}; do echo current/total ... some other codes done I want to calculate ...
-4
votes
0answers
15 views

BASH— after getopts continues after exit [on hold]

in getopts(probably) it has two functions in it. One of them has exit at the end and there is also exit at the end of the option b. When I call it like this: ./name.sh -b. (without required argument) ...
3
votes
1answer
15 views

vipe misbehaving on bash process substitution

I have the following simple command: $ echo <(vipe) I expected it to open a vim buffer, which I can edit, then when I'm done, echo the name of the temporary file assigned to hold the vim buffer ...
3
votes
1answer
21 views

Moving sub-directory to new parent directory where the new directory name is incremented by 1

I am attempting to move a sub-directory from one parent directory to another for hundreds of instances, while changing the name of the sub-directory during the move. My directories are a set of ...
2
votes
1answer
38 views

what are practical uses of stdbuf or nohup?

I have to finish a writeup of a few coreutils commands for a course at the moment, and I can't think of a starting point for a small practical code example that demonstrates the potential uses of ...
0
votes
1answer
47 views

What does $'text' do exactly in Bash? Can it be used in Zsh?

I recently run into the following proposed solution: cat results.csv | tr $'\x01' \\t > result.csv to convert a malformed csv file (one that uses \x01 unicode as a separator) into a correct one. ...
0
votes
1answer
47 views

Why are my variables not reset to zero?

In the below loop, I try to reset the values of two variables (totalentries and totalusedbytes) to zero, but I can see from the results that it never happens. Thus each loop continues to add to the ...
0
votes
1answer
43 views

Shell— print only certain lines from output

I need to choose from output only lines where number is bigger than chosen number. For example x=27 and I need to find only lines where the number in first column is bigger than that x. In this ...
2
votes
1answer
24 views

Removing line numbers from `od`'s output

Is there any flag to od to make it not output line numbers in the result?
-2
votes
0answers
33 views

Combine lines of file to string [duplicate]

I am trying to have a file inputted by my script and put into a string to be put into another file. ./script.sh -u uuids.txt -s servers.txt Each file will have a list with each value being on it's ...
2
votes
1answer
59 views

bash: how to save state on prompt evaluation [duplicate]

I want to put duration of last running command in command prompt, f.ex: user@host$ sleep 360 6m user@host$ Also, I want duration to not show up if it is less than some minimum threshold (say 30 ...
-2
votes
3answers
33 views

Syntax error when trying to cut part of a variable

If I write a simple echo $i, I have no problem: it shows me the variable. But if I try do something with it $($i|cut -d"." -f1-3) then I get an error messages : -bash: /...file.backup: Permission ...
0
votes
3answers
56 views

How to make backticks accept variables as variables?

This is my code: #!/bin/bash machine_we_are_looking_for=$1 user_defined_new_machine_location=$2 condition_while_one=true condition_while_two=true echo "test 1" while $condition_while_one do ...
0
votes
0answers
11 views

Google Chart - Using Bash to dynamicaly add data - collected from a MQTT stream

I can collect data from the MQTT stream, I was curious to know 'how' I can push this data dynamically to the Google Charts with BASH/Shell script? This script will eventually be running daemon ie 'run ...
0
votes
1answer
72 views

Temporary file BASH

does this piece of code creates temporary file? Because I am not supposed to use them and I only found out yesterday that even sed -i creates it. So I can be sure. Thanks while read line; do if [[ ...
1
vote
0answers
37 views

Bash script to get the result from rsync transfer and zip it as a directory in the original directory

OK, I guess this is weird. I have a small stage.sh script very simply has a bunch of commands: if [ "$(whoami)" == 'David' ]; then rsync -a --delete-excluded --exclude-from=.stage_rsync_rules ...
2
votes
2answers
20 views

Can someone explain exactly what is happening with single quotes and double quotes with process IDs in the below example? [duplicate]

[root@localhost ~]# echo $$ 16991 [root@localhost ~]# bash -c "echo $$" 16991 [root@localhost ~]# bash -c "echo $$" 16991 [root@localhost ~]# bash -c 'echo $$' 21062 [root@localhost ~]# bash -c 'echo ...
2
votes
2answers
79 views

How to remove duplicate files using bash

I have a folder with duplicate (by md5sum (md5 on a Mac)) files, and I want to have a cron job scheduled to remove any found. However, I'm stuck on how to do this. What I have so far: md5 -r * | ...
1
vote
1answer
45 views

Why are files and directories colored in different ways? [duplicate]

On Ubuntu 14.04, in bash under gnome terminal, Why are files especially directories colored in different ways? The green colors hide the text to me (How about to you?). Is it done by terminal or ...
0
votes
0answers
24 views

Would this command delete only the lines containing specific words within a delimited area? [duplicate]

Please see my previous question here. No one seems to be following up on it, so I have tried to have a go myself: sed '1 { /^---/ { :a N; /\n---/! ba; /^Title: \|^Place: /d} }' filename Would this ...
20
votes
7answers
954 views

`command .*` acts on the parent directory

Someone of our team wanted to recursively change the user permissions on all hidden directories in a users home directory. To do so he executed the following command: cd /home/username chown -R ...
0
votes
0answers
60 views

Combine lines of file to string [on hold]

I am trying to have a file inputted by my script and put into a string to be put into another file. ./script.sh -u uuids.txt -s servers.txt Each file will have a list with each value being on it's ...
0
votes
0answers
48 views

Replace a string with another string in a text file [on hold]

I want to replace a string that is in the file file1 with another string. I tried sed -i -e "s/chaines1/chaine2/g" file1 but the problem is I can't pass the two strings on the command line ...
2
votes
3answers
54 views

What happens if I pass too few parameters to a shell function?

I would like to ask about passing parameters into functions. I tried this: function_name $var1 $var2 but usually (sometimes it printed error) it didn't make any difference whether I passed them or ...
2
votes
1answer
33 views

Can I re-login a disconnected session? [duplicate]

For some network reasons, my previous SSH sessions to server have disconnected. When I create a new session, I find the previous session still exist: [root@localhost ~]# who root pts/0 ...
3
votes
1answer
34 views

how to send output of curl request to 2 separate commands

I'm piping the output of a curl request to gawk so that I can pull some data. The gawk code is already working if I'm searching through the html file which curl request produces. However, I was ...
2
votes
3answers
56 views

One-liner for getting an IP address of an internal DNS name?

I have an internal DNS name for which I'd like to get the IP address. Is there a nice Bash one-liner I can issue to convert internalip1.mydomain.com into 10.10.10.10?
2
votes
1answer
92 views

grom() keyword in bash throws unexpected '(' token

I'm not entirely sure why I'm getting the error in my .bash_profile syntax error near unexpected token `(' when I use the keyword grom() for my function. I wanted to create a bash function that ...
4
votes
2answers
91 views

Can 'ssh <host> <command>' be configured to always load server-side startup files?

I would like run remote ssh commands and have them always load server-side startup files by default. I am looking for a solution that does not require: configuration by root adding extra boiler ...
1
vote
2answers
42 views

Remove paragraph from file

I have a file (file.php) like this: ... Match user foo ChrootDirectory /NAS/foo.info/ ForceCommand internal-sftp AllowTcpForwarding no GatewayPorts no ...
1
vote
1answer
53 views

Brace expansion not working in a script

for i in {1..40} do echo $i done I got {1..40} and I would like to have something like 1 2 3 and so on so I can use the variable i inside a command's parameter.
0
votes
1answer
38 views

User Input Bash Script

I am trying to make a Bash Script that has 4 choices and prompts the user to select an option. Each option corresponds to a Linux Command operation. Can someone give me a bash example on how could ...
0
votes
4answers
60 views

Copy same specific parts of a file to another file

How can I copy same specific parts of a file to another file? In the first file, I have: user01: Id name nationality user02: Id name nationality . . . I want to copy each piece of information to a ...
1
vote
2answers
32 views

Bash autocomplete: does not list files or directories

In my bash terminal, I would usually press tab twice to get the file and folder list. For instance cat 2XTAB would list all files and folders in the present directory and cd Proj2XTAB would list all ...
2
votes
1answer
36 views

How to verify the target of a symbolic link points toward a particular path

Within a bash script, I know I can check if a file is a symbolic link with the following syntax if [ -L $path ] Does any one know how I would test if that path was linked to a particular path? E.g. ...
0
votes
0answers
33 views

Compare specific word counts without variables or expr

I am tasked to write bash command to count number of specific words (given in file) in 2 files and write an error message if number of these words in first file is more than 3 times biggen than in the ...
0
votes
0answers
30 views

How to get and print a user's public IP address in a Shell Script? [duplicate]

I've just completed a lengthy installation script that deploys a Ruby on Rails application unto web servers. At the end of this script, I'd like it to print something along the lines of: "Installation ...
0
votes
0answers
16 views

MYSQL dump of tables that start with docs_ from one server to another

The headline says it :) I would need script that dumps all tables from 'ads' database on different server(s2) starting with 'docs_' copied to my server(s1). Any hints? The reason that I need script is ...
1
vote
1answer
31 views

Search for text inside java command output

I have a folder which have multiple Jar files. * dummy.jar * myjar-xx.jar * myjar-yy.jar Using find, I need to find first file starting with "myjar" Now, I want to grep the contents of ...