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.

learn more… | top users | synonyms

1
vote
2answers
29 views

how to set alias of command in bash that contains both single and double qoutes [duplicate]

I am not able to set alias of hexdump -e '/1 "%_ax) "' -e '/1 "%02X" "\n"' I have tried following methods but failed: alias analyze=\'hexdump -e '/1 "%_ax) "' -e '/1 "%02X" "\n"'\' (note the ...
5
votes
2answers
30 views

What exactly happens if input and output file is the same?

Let's say that I execute following command: tr a-z A-Z < file > file There are two redirections: < file and > file. Both are processed before tr command and as far as I know, if there ...
1
vote
1answer
30 views

copy array with array name inside string in bash

In bash 4.3 script, I have variables: environment="local" config_local=("a" "b" "b" "d") copy_from="config_${environment}" I want to copy values from array with name stored in copy_from to another ...
3
votes
3answers
48 views

Sudo-like remembrance of passwords for own scripts

I have a script which requires a password for authenticating a web service. A single password for a pre-defined user will suffice, and the password should if possible be stored securely (not plain ...
0
votes
0answers
28 views

Why does bash's readline eat tab?

My question is from Delimiter in word splitting Why does Bash not respond when I hit Tab key? What other keys does Bash eat?
0
votes
1answer
53 views

Running .sh Script With Sudo Results In Different Output

I'm seeing some really strange behavior in a script I'm working on.What I have is an svn hook that gets run whenever a commit is made to an svn repo. It runs a sqsh command that generates another ...
2
votes
1answer
22 views

How can I launch irb from a bash script, execute some commands, then pass the irb session to the console?

I am creating a ruby gem and to speed my testing I wrote a script to build and install my gem, then to open irb for me to manually poke around. How can I run the following ruby commands before ...
0
votes
2answers
50 views

How to fix vmware header error?

I'm trying to run vmware on my kali linux 2.0 box, because I want a lab to practice my skills on, but vmware won't launch it's giving my an error message saying "C header files matching your running ...
0
votes
1answer
25 views

How do I output stderr/stdout of my script to both a file and the console?

I'm using Amazon Linux and writing a script in bash. I want to output both stderr / stdout (preferably in the order that they occur) to a file as well as the console. However, this command isn't ...
0
votes
1answer
30 views

Why is nothing shown from variable expansion?

Why does nothing come out of $IFS when: $ echo $IFS while $ printf '%q\n' "$IFS" $' \t\n' $ echo "$IFS" | od -bc 0000000 040 011 012 012 \t \n \n 0000004
0
votes
1answer
34 views

command /opt/bin/date --date '-15 minutes 2016-04-27T14:14:47' producing result many hours before stated time

I'm using the following command in an attempt to work out the time 15 minutes before the timestamp: /opt/bin/date --date "-15 minutes 2016-04-28T16:58:55" '+%Y-%m-%dT%H:%I:%S' The problem is the ...
-1
votes
2answers
47 views

Where can I practice my Python and Bash scripting? [closed]

I wanted to practice my bash scripting skills and python skills and wanted a good book or a site where I can practice and get excellent skills please. Any recommendations please.
1
vote
3answers
83 views

Delimiter in word splitting

In Bash, word splitting is a step in command line processing. From Bash Manual The shell treats each character of $IFS as a delimiter, and splits the results of the other expansions into words ...
2
votes
4answers
47 views

How to catch and handle nonzero exit status within a Bash function?

Say I have the following (pointless) Bash function: myfunc() { ls failfailfail uptime } I run it as follows: myfunc || echo "Something is wrong." What I want to happen is ls runs (as ...
0
votes
1answer
28 views

Correct syntax for inputting date variable into date calculation code

In my script, the following code successfully produces a timestamp variable for $n in the format 2016-04-28T15:47:48 for n in $(perl parsetime.pl | sed "s/.....$//") do echo $n result is: ...
1
vote
1answer
34 views

Trying to copy/paste long script with multiple EOFs, Terminal starts running half-way through

Was trying to create a text block that I could just copy and paste into a Terminal window to accomplish something (in this case, create a systemd script to do maintenance on MySQL dbs, create a timer ...
1
vote
1answer
44 views

Bash print current line, line's output, and linebreak to file

I've got a txt of a bunch of domains I need to run dig +short mx on. I've got a script set to run the command, print it to a results.txt with: ./dig_domain_mx.sh > results.txt Downside is, I ...
1
vote
1answer
59 views

How does Bash process a command line?

From Learning the Bash Shell by Newham: Each line that the shell reads from the standard input or a script is called a pipeline; it contains one or more commands separated by zero or more pipe ...
4
votes
2answers
44 views

Store quotes in variable to use as command line parameter Bash

I am writing a script to call a command (weka, if you are curious) a couple of times with some different parameters. One of the parameters, '-search "< stuff >" ' needs to be quoted. In some ...
2
votes
1answer
38 views

How do I check for the existence of a process without a failed exit code being returned?

I’m using Amazon Linux. I want to start a process provided one isn’t running already. This is a bash script I embed within a Jenkins Maven job. So I have pids=$(pidof /usr/bin/Xvfb) if [ ! -n ...
3
votes
3answers
198 views

adding special characters to folder names

I have a very long list of folders with the following naming convention ABS1789_2563-01 ABS1789_2563-02 ABS1789_2563-02 . . . How can I add " - " between ABS and 1789 then replace "_" by "-" ...
5
votes
1answer
52 views

Cannot grep jobs list when jobs called in a function

I can grep the output of jobs, and I can grep the output of a function. But why can't I grep the output of jobs when it's in a function? $ # yes, i can grep jobs $ jobs [1]+ Running vim ...
0
votes
0answers
21 views

Creating an iso file from a Dual layer dvd

I created an iso file using mkisofs "for linux OS: RH 7". Mounting the image shows the same folders of the original source from which the iso is generated. However when using this iso image to ...
0
votes
1answer
22 views

Dynamically write bash script from another?

I am trying to dynamically create and write to a file a bash script from from a current bash script. echo "## Get the IP of the system that was assigned #!/bin/bash ip=$( hostname -i | xargs ) echo ...
0
votes
1answer
21 views

Including milliseconds in a Script?

sudo hexdump -v -e '1/1 "%02x\n"' /dev/ttyUSB0 | awk '$1=="ed" { getline byte1 getline byte2 number = strtonum("0x" substr(byte2,2,1))+2 ...
0
votes
2answers
42 views

How can I forward #! through a bash script to provide indirection

Sorry if the question statement wasn't very clear. I'd like to have a bash script that I can edit to change the behavior of a bunch of other scripts. For instance--I have some groovy scripts. they ...
1
vote
2answers
49 views

Failed to open config file '/dev/fd/63', error: No such file or directory for wpa_supplicant

When I do this: sudo wpa_supplicant -D nl80211,wext -i wlp4s0 -c <(wpa_passphrase "some ssid" "password") I get Successfully initialized wpa_supplicant Failed to open config file '/dev/fd/63', ...
-3
votes
1answer
29 views

Code to calculate 15/30 minutes before specified timestamp (GMT) in ISO 8601 format

I am working with a timestamp which is in the following format which I am told is know as ISO 8601 : 2016-04-27T14:14:47.836Z I would like to be able to calculate the timestamp both 15 minutes and ...
1
vote
1answer
25 views

How to get pid of subprocess from the subprocess itself

How can I get pid of a subprocess from the subprocess itself? foo() { echo pid=$$ echo spid=$! echo bpid=$BASHPID } echo PARENT_PID=$$ foo & wait on first run I get: PARENT_PID=17112 ...
8
votes
4answers
558 views

Bash program not executed if redirection would fail

In bash, I notice that if a command using redirection would fail, any programs which run prior to that are not run. For example, this program opens the file "a" and writes 50 bytes to file "a". ...
4
votes
1answer
37 views

What does the history command !# do?

From the manual pages on history: Event Designators An event designator is a reference to a command line entry in the his‐ tory list. Unless the reference is absolute, ...
-1
votes
2answers
43 views

Use of && and || operators to handle the result of the same command

In bash, is it possible to use these two operators to handle both of the exit statuses of the same command ? or if I want to handle both cases, I have to use an if statement ?
0
votes
3answers
49 views

sed substitution

I have a string as follows: /test/test/ 12 /test/test My goal is to turn it into: /test/est/ 12 /test/test This is the command: echo "$x" | sed 's@\(/*/\).@\1@g'" I am using at the moment but ...
0
votes
2answers
22 views

SFTP suppress all messages except errors

I want to 'put' a file from local system to FTP server using sftp (only) from bash script. I want to suppress all messages except errors: sftp $user@$server 2>&1 1>/dev/null <<EOF ...
2
votes
2answers
33 views

Get specific result from function

Is there a way to return a specific value in an echoing function? return allows me to return an exit status for the function. I need to return a more sophisticated data structure such as an array, or ...
0
votes
4answers
22 views

Echoing piped output [duplicate]

Is there a way to echo output that being piped to the next command? For example lets say that I can reading filenames from a text file and then running a command on that file: cat files.txt | xargs ...
1
vote
2answers
45 views

cd to original location when recording session with “script” command

I have script log.txt in my bash profile; that creates a new sub process and records my entire session to log.txt. When I press cmd+t to open a new terminal usually this will open one in the same ...
1
vote
1answer
20 views

JSON with variable key in bash

In the bash script below, I have JSON object and need to have key hostname with random name, like host-$NAME (i.e. host-1, host-3). How to do it ? #!/bin/bash NAME=($(( ( RANDOM % 10 ) + 1 ))) ...
-1
votes
0answers
29 views

Shell Script- Conversion script for reading and updating data to new column

I am writing a conversion script that will help me to read the data from a column and move it to a new column. I want to read data row by row for column cross_reference and copy this data to newly ...
0
votes
2answers
47 views

Binding Timestamp with Hexdump?

I am running a script which is given below, sudo hexdump -v -e '1/1 "%02x\n"' /dev/ttyUSB0 | Many Pipes | gawk '{ print strftime(":: %s"), $0 }' Here the data is being hex dumped with timestamp ...
3
votes
2answers
40 views

Should suspended application in the background (by ctrl+z) still run or should it stop running?

I run Firefox with command xinit /path/to/firefox/binary and it opens a display with Firefox running on it. Then I push Ctrl +Alt+F1 to go back to console and then I push Ctrl+z to suspend the ...
2
votes
2answers
154 views

What's the fastest way to get n-th line of a text file [duplicate]

Given a file with m lines, how to get the n-th line. m can be smaller than n sometimes. I have tried: method1: sed -ne '10p' file.txt method2: sed -ne '10p' <file.txt method3: sed -ne '10{p;q;}' ...
0
votes
2answers
36 views

Sed replace not functioning as expected

I want to replace listen = 127.0.0.1:9000 by listen = '/var/run/php56-fpm.sock' sudo sed -i 's/listen = 127.0.0.1:9000/listen = \'/var/run/php56-fpm.sock\'/g' /etc/php-fpm.d/www.conf Error: bash: ...
7
votes
2answers
313 views

reason for exec in wrapper scripts

I have seen wrapper script examples which in a nuthell are following: #!/bin/bash myprog=sleep echo "This is the wrapper script, it will exec "$myprog"" exec "$myprog" "$@" As seen above, they ...
0
votes
3answers
50 views

Compress and remove original directory with limited storage

On my 3 TB external hard drive, I have a 2.7 TB directory containing relatively small files. I would like to compress this 2.7 TB directory and remove it to keep only the compressed version. The issue ...
0
votes
1answer
30 views

Bash script using mysql command with variables failing

I have a script to clone a vhost and associated db - however one of the mysql commands doesn't work. It fails and ends up outputting the mysql version number and 'how to use' info as if it hasn't been ...
0
votes
2answers
28 views

Having trouble deleting specific directories within a specific parent directory

I’m using Amazon Linux, bash shell. I’m trying to write a statement that will delete all child directories named “target” within a specific master directory. I would like to write things such that ...
0
votes
1answer
39 views

Vim saved file not updating on webpage

I am attempting to update an HTML file on my server, but when I do so it doesn't appear to be updating, but rather, serves an old copy instead. I went through the usual process of pressing :w and ...
1
vote
1answer
47 views

Creating a complex variable content by hand

I am creating a shell script dynamically and sending it to a remote server for execution. All is working except when I try to inject a variable with content coming from a file with multiple lines, ...
0
votes
0answers
27 views

What is the meaning of :- in unix? [duplicate]

Trying to understand the existing script where they have assigned ${3:-} to variable. Script : partition_parameter=${3:-} if [ -z $partition_parameter ]; then readonly drop_partition=false ...