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
0answers
2 views

Shell expansion for arguments rather than variables?

For example: mkdir touch ~/{1,2,3} Creates directories ~/1, ~/2, and ~/3. brew {install, update, doctor} obviously amounts to nonsense as interpreted by the shell. This may not be the best ...
0
votes
1answer
12 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 ...
6
votes
1answer
245 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 ...
3
votes
2answers
61 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
1answer
27 views

Read the last line of tzselect

I am trying to read the result of tzselect into a bash script in order to set the Timezone pragmatically. Code snippet should look like /usr/bin/tzselect #Read last line of tzselect and cp to ...
0
votes
0answers
11 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 ...
0
votes
1answer
36 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 ...
2
votes
1answer
61 views

Printf formatting with variable format - what does this var reference?

I am experimenting with printf formatting in bash and I ran across this piece of code: #/bin/bash divider=============================== divider=$divider$divider header="\n %-15s %8s %10s %11s\n" ...
0
votes
1answer
33 views

How to convert Ubuntu init script to Amazon Linux AMI init script?

I had a Ubuntu based Amazon EC2 server where I was running my java based application. For this I had written a init script which was running perfectly and as follows #! /bin/sh # set the environment ...
0
votes
1answer
32 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
32 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 ...
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: ...
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
1answer
29 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 ...
0
votes
2answers
87 views

How to delete specific lines within a certain area?

I want to delete some specific lines in the YAML front matter: --- Author: aaaa Title: bbbb Time: cccc Place: dddd ... Lets say I wanted to delete only the lines in the front matter that contained ...
25
votes
4answers
18k views

What is the difference between “sort -u” and “sort | uniq”?

Everywhere I see someone needing to get a sorted, unique list, they always pipe to sort | uniq. I've never seen any examples where someone uses sort -u instead. Why not? What's the difference, and why ...
2
votes
2answers
4k views

grep output of expect script

I'm trying to run some expect language, and grep/parse the output all in one script. I want to grep the output of and look for "error" (I should note that standard linux commands like awk, sed, grep, ...
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 ...
2
votes
3answers
5k views

Can xxd be used to output the binary representation of hex number , not a string?

I would like to generate a raw binary packet from hex in the command line for the purpose of testing a protocol. I'm hoping its simpler to do it this way than writing an aplication. Here is what ...
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
31 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
28 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 ...
5
votes
3answers
326 views

Display Non-Zero Return Status in PS1

I want to include the return status in my prompt. (Easy add '$? ', right?) However, I only want the status returned (and trailing space) if non-zero. Example: sd ~ $ false 1 sd ~ $ true sd ~ $
2
votes
4answers
117 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 ...
-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 ...
1
vote
1answer
31 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 ...
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= ...
2
votes
3answers
159 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 ...
4
votes
2answers
96 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 ...
20
votes
7answers
1k 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 ...
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.
9
votes
3answers
394 views

How to customize Bash command completion?

In bash, it's easy enough to set up customized completion of command arguments using the complete built-in. For example, if, for a hypothetical command with a synopsis of foo --a | --b | --c, you ...
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 ...
8
votes
3answers
680 views

Escape sequences in output of script called from ncurses application

I'm currently running mcabber as my Jabber client (which uses ncurses) in a tmux session on my homeserver. Locally i run iTerm2 as a terminal emulator, which supports the triggering of growl ...
2
votes
2answers
35 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 ...
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 ...
4
votes
2answers
177 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: ...
-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
22 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. ...
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 ...
11
votes
10answers
8k views

How do I create a directory in all subdirectories?

Suppose I have a directory structure like this: $ [~/practice] ls a/ b/ c/ d/ Now I want to create a directory tmp1 in all sub directories of practice and I do this: $ [~/practice] mkdir */tmp1 ...
9
votes
3answers
16k views

Resolving MAC Address from IP Address in Linux

I need to write a bash script wherein I have to create a file which holds the details of IP Addresses of the hosts and their mapping with corresponding MAC Addresses. Is there any possible way with ...
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 ...
0
votes
1answer
4k views

rsh shows “poll: protocol failure in circuit setup”, why?

In the starting rsh worked properly, but after making some changes it shows some error [changes are shown in the end of this question, see that], I am sharing the same. Command $ /usr/bin/rsh ...
-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 ...
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 ...
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
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 ...
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. ...