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

How to copy files from local datacenter to local datacenter and have some failover cases?

I have a script which knows about on which HOSTNAME it will be running as it has the HOSTNAME variable which tells about this and it is being passed from outside. I want to check which datacenter that ...
0
votes
2answers
31 views

Bash script strange behavior with echo - printf in a file

I want to print part of the content of a .csv file in another file if there is a match with some condition: The csv content is like this abc test;ABCtest.it xyz test;XYZtest.com I read the content ...
1
vote
2answers
23 views

Use for loop in find exec

-> find .. -name bin -exec for file in {}/* ; do echo $file ; done \; -bash: syntax error near unexpected token `do' What is the proper syntax for this command ?
1
vote
0answers
22 views

Python embedded in bash not working [migrated]

I want to embed a small python script inside a bash script so that I can send a json object to a socket. I have tried the following code: python -c "$(cat << 'EOF' import socket import json ...
1
vote
0answers
26 views

How to determine interface RUNNING state without ifconfig?

Some background: sometimes my wi-fi connection suddenly goes down so I type sudo ifconfig wlan0 and check for the word RUNNING. The corresponding line looks like: UP BROADCAST RUNNING MULTICAST ...
2
votes
0answers
31 views

Is it possible to show the current history line number when performing reverse search in bash?

Pressing Ctrl+R and typing py results in: (reverse-i-search) `py´: python I would like it to be this way: (reverse-i-search) `py´: n python where n is the history line number. I did not find an ...
1
vote
1answer
46 views

How can I skip empty files with sed?

I am using sed like this: sed -e 's/ *| */|/g' ${array_export_files[$loopcount]}>>$TEMPDIR/"export_file"_${testid}_${loopcount}_$$ under a while loop but problems come when the file is ...
0
votes
0answers
39 views

shell script prompting for password but not taking it while doing tar

In my shell script, I have following lines: function tarIt() { FILE_OWNER=$1 TAR_FILE_NAME=$2 FILE_NAME=$3 su - $FILE_OWNER -c "tar -cvzf $TAR_FILE_NAME $FILE_NAME > /dev/null ...
3
votes
2answers
333 views

while: command not found

I'm trying to do this as an April Fool's prank: make a linux machine display a message in the shell every few seconds. My thought is to achieve this by starting an infinite loop that runs as a ...
0
votes
1answer
13 views

Unix KSH or Bash Renaming of xlsx files tab [on hold]

I have a file of extension .xlsx which contains various sheets and the name of those sheets are getting displayed at bottom of file as Sheet01 Sheet02 Sheet03 Now I wanted to rename those sheets ...
1
vote
1answer
41 views

How to distinguish between output of numerous similar commands

Say I am issuing ls -la in a directory that has hundreds if not thousands of files, then changing to another directions and issuing ls -la. I then need to scroll up to see what files are in the most ...
1
vote
3answers
123 views

Shell expansion for arguments?

For example: mkdir ~/{1,2,3} Creates directories ~/1, ~/2, and ~/3. It equates to: mkdir ~/1 mkdir ~/2 mrdir ~/3 But, using the same syntax in the case of CMD < argument > : brew {install, ...
-1
votes
2answers
27 views

How to count the number of parameters in a given line within a CSV file

I've got accumulated data in a CSV file as follows: Parameter_1,Parameter_2,Parameter_3,Parameter_4,Parameter_5,Parameter_6 Parameter_1,Parameter_2,Parameter_3,Parameter_4 ...
3
votes
2answers
91 views

brace expansion and * expansion

Assume in the working directory, there is only one djvu file. I would like to backup the file into a file with file name having extra .bk at the end. cp *.djvu{,.bk} copies the djvu file into a file ...
0
votes
0answers
16 views

Datum in a CSV file to pushed/sent over to Google Charts

I have a CSV file, where the accumulated data is as such (just a snippet): ... 20150327,TEST-MACHINE-091,9,10 20150327,TEST-MACHINE-092,2,7 20150327,TEST-MACHINE-093,1,4 ...
6
votes
1answer
267 views

In which situations are PS2, PS3, PS4 used as the prompt?

When I log on into the shell I see the prompt whose value is stored in PS1. I also encountereded another prompt (but do not know which one) when I used the here-document syntax: bc << HERE ...
0
votes
1answer
46 views

Shell script to compare two tables and perform operations on their columns

I have two tables like the following: Table 1 TABLE_NAME COUNT ------------------------------ ------------ AIN_EDP_SCRIPT 33 AMA_CALLTYPE_LOOKUP ...
0
votes
1answer
38 views

Modify part of line if keyword is found using sed? [duplicate]

I want to modify a line if a specific keyword is found in a line. CS_CODE, SM_NUM, PORT_NUM, DEV_PORT_NUM, DIRNUM, MAIN_DIRNUM, BILL_NO, ADR_NAME In above line, if 'PORT_NUM' is present then ...
0
votes
3answers
35 views

grep log lines of a specific id request

So, I have the following log sample: 2015-03-30 10:19:44,200 DEBUG [Default : 1] [Application:ABC BIW: IDA:6d87de8e-1276-4496-b49d-dd4cd375cbe4 Info:P23 Code:ABCD] A log message 1 2015-03-30 ...
2
votes
1answer
24 views

Need to press enter to get prompt after executing udev script

I have set a simple udev rule for my Raspberry Pi (Debian) to automatically mount an USB HDD. It just runs a script which mounts all devices in /etc/fstab since it's the only one I have and I'm going ...
1
vote
0answers
34 views

bash scripting : using expect

I am facing an issue when I run simply these commands. The remote server want to pass "yes" to add the key in RSA file because first time connection established with scp. commands are given below ...
2
votes
0answers
33 views

Bash: “history number” vs “command number”

While Googling how to customize my shell prompt via the PS1 variable, I'm seeing tables of special characters that can be used. In particular: \! the history number of this command ...
0
votes
1answer
29 views

bash script taking input [on hold]

I have written a bash script. It is launched like this: ./myscript.sh $IP COMMAND-FILE In COMMAND-FILE I give commands which I have to run on remote server. But now I have to use another script in ...
0
votes
0answers
44 views

Incremental search [on hold]

How to enable incremental command-history search in terminal, for all users, in debian? I have to edit the /etc/bash.bashrc right? I am refering to this: ...
1
vote
2answers
42 views

Parsing C Style Multiline Comment

I want to filter non-commented javascript with sed and output the line number Here is the example: /*! * jQuery UI 1.8.17 * * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about) * Dual ...
1
vote
1answer
30 views

How to use convert command with bash to resize all images in a given directory?

I want to resize all PNG files in ~/somefolder/ whose filenames are NOT started with tn_ to 50% of its original size and rename the output file with a tn_ as its prefix and its original name. I know ...
1
vote
1answer
32 views

awk script to rearrange similar rows

I want rearrange about 5 million rows (with 300 columns) into groups. Data looks like the following: where there were various experiments (column 2) conducted at different locations (column headers ...
2
votes
1answer
25 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
27 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= ...
1
vote
1answer
20 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
160 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
4answers
118 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
41 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
20 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
25 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
votes
1answer
11 views

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

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 ...
2
votes
2answers
37 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
180 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
31 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
16 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
16 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
24 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
45 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
49 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
44 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
38 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
71 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
35 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 ...