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.
0
votes
0answers
3 views
Why do some programs disobey quoting rules?
I want to print a string and be sure all $VARs inside it are not expanded to their values.
That's why I enclose my text in single quotes.
Example:
echo '$SHELL';read -sn 1
This command displays ...
0
votes
1answer
6 views
Arguments and positional parameters in `bash -c <some-command>`
Bash Manual says about bash -c <some-command>:
Read and execute commands from the first non-option argument after processing the options, then exit. Any remaining arguments are assigned to ...
-2
votes
0answers
9 views
What kinds of commands can be run with `bash -c`?
When the command is a bash script, a function, or a compound command
(e.g. a pipeline), can the command be called with bash -c?
Or can bash -c only work with a builtin or external simple ...
0
votes
1answer
11 views
What does `bash date` mean?
$ bash date
/bin/date: /bin/date: cannot execute binary file
$ bash -c date
Thu Apr 14 19:27:08 EDT 2016
What does the error message of bash date mean? What does bash expect date to be?
1
vote
3answers
25 views
What is the difference between running a command directly and with `bash -c`?
For a command (builtin or external), what is the difference of
running it directly in a bash shell process and with bash -c in
the bash shell? What are their advantages and disadvantages
...
0
votes
1answer
14 views
assign string components into variables [duplicate]
Looking for a smarter way to do something I'm doing already.
I have a string: "firstbit.secondbit.thirdbit.fourthbit.fifthbit.sixthbit"
The content between the periods changes, but the delimited ...
1
vote
2answers
31 views
Why when I try to execute a program as normal user I get denied, and when I execute it with sudo I get “Not Found”
In order to execute mysqlbackup I have to execute it as root.
Here's the example when I execute it as normal user:
mysqlbackup --compress --user=root --socket=/var/lib/mysql/mysql.sock ...
1
vote
2answers
41 views
bash - All possible combinations of words from different files
I have n files with one word per line
file 1 file 2 file 3 ...
1_a 2_a 3_a
1_b 2_b 3_b
1_c 3_c
I want to write a bash script that takes all this files ...
1
vote
1answer
18 views
bash set -o errexit problem or the way of incrementing variable?
I have a shell script incrementing a variable like in the example below with set -e:
$ var=0; echo $?
0
$ ((var++)); echo $?
1
$ ((var++)); echo $?
0
$ ((var++)); echo $?
0
$ echo $var; echo $?
3
0
$ ...
5
votes
3answers
299 views
Piping a command through a color filter
Does something like this exist in Unix?
$ echo "this should show in red" | red
$ echo "this should show in green" | green
$ echo "this should show in blue" | blue
Here I don't mean for literal ...
0
votes
1answer
10 views
openSUSE frozen on login screen, refuses to return to GUI [on hold]
I just came back to my recently installed (overnight last night, just started using it today) openSUSE installation to find it frozen on the lock screen. After various attempts to get it to unfreeze I ...
0
votes
1answer
15 views
bash - npm not found, though installed
ph@vm:~$ uname -a
Linux vm 4.2.0-16-generic #19-Ubuntu SMP Thu Oct 8 15:35:06 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
ph@vm:~$ which npm
/home/ph/.nvm/versions/node/v4.0.0/bin/npm
ph@vm:~$ npm -v
...
0
votes
2answers
42 views
Get the latest value of an environment variable is a bash shell script
I wonder how can we get the latest value of an environment variable in a bash shell script.
Problem I am having is, I have a environment variable which can be changed externally multiple times. But ...
1
vote
5answers
68 views
How to go to each directory and execute a command on specific file?
How do I write a bash script that goes through each directory inside a parent_directory and executes a command on specific file.
The directory structure is as follows:
Parent_dir/
dir1/
acc.bam
...
0
votes
0answers
14 views
How to make cron job which suspends computer before specified time of the day
I am trying to make script which suspends computer if it is used before specified time of the day or if it is used too long.
#! /bin/bash
...
0
votes
0answers
18 views
Automated port change
I want to Create a Bash file that a user can execute to change the port a service runs on.
Essentially all I have to do is replace a number in a line of text with another number generated by a list. ...
0
votes
1answer
9 views
Filter for remote server response from netcat SMTP scan
I am using netcat to test if remote exchange server (lets call it exchange1) is online with this code.
nc -w 3 192.168.130.17 25
I want to create a file that has that servers name if and only if ...
1
vote
1answer
22 views
Problem saving standard output to variable
Looked some for an answer, but not finding anything that sticks out as a solution.
I'm trying to make a bash script, and in it I need to save the output of git rev-parse --show-toplevel to a ...
0
votes
2answers
25 views
Reconstructing a tab-separated record in bash not working
I need to parse a tab-separated CSV file using bash, examine the contents of the record, and, if the record meets certain criteria, add it to an array. Basically, I want to filter records out of a CSV ...
0
votes
2answers
27 views
How does the shell decide which of same-name keyword, builtin, and external command to run? [duplicate]
When there are same-name builtin, keyword and/or external command, what is the order in which the Bash shell decides which to run?
For example,
keyword time and external command time,
builtin ...
0
votes
0answers
11 views
Long response time when using chroot
I have a Ubuntu 14.04 LTS Server and yesterday the response time of the server was quite long, meaning when using simple commands like:
ls -al
it would take up to 20 seconds to respond in a very ...
0
votes
2answers
22 views
how to properly log the output of a console program that frequently updates “parts” of the screen, resulting in a messy log file?
I have some Java executable (jar) that is run my some shell script from a cron job once every night. That executable does not print log statements "as usual" just by printing them out in a sequential ...
2
votes
0answers
15 views
How to resize images to fit all content on minimal canvas?
I'm trying to quickly check for differences between separate iterations of a web site using ImageMagick's compare. But it refuses to compare images of different size, and doesn't seem to have an ...
2
votes
0answers
92 views
have I found a bug in BASH?
EDIT: the bug disappears by version 4.3.8.
I am using GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu). I believe I have found a bug. Would like to know if perhaps I'm missing something ...
1
vote
2answers
45 views
How can a command in a pipe read from a keyboard? [duplicate]
I randomly tried to execute the following command in bash1
cat /some/file | ssh user@machine 'cat >/destination/file
There are no keys installed on the remote machine, so the only way to ...
1
vote
3answers
22 views
execute command on a defined range of directories
Is it possible to 'partition' a directory listing - say in to blocks of some number, to perform different actions on each 'range'?
For example, lets say I have the following directories inside ...
0
votes
2answers
32 views
Copying script files using wildcards
We have an SFTP location which is shared by two processes. Now we have a situation when we need to filter based on the filenames before copying.
ClientA12345.out
ClientA44378.out
ClientB23478.out
...
0
votes
3answers
30 views
Modifying a byte with bash, dd isn't working
I'm trying to modify a byte with bash,
So I will write the bytes before the offset, then the byte to modify, and the rest of the file.
But the following script doesn't work as expected
Anyone ...
0
votes
2answers
37 views
Brace expansion does not work
In Bash, I want to rename a file so that the prefix up to - is removed, but why does it not work with brace expansion?
$ ls
Thomas Anderson, Michael Dahlin-Operating Systems
$ mv {Thomas\ Anderson,\ ...
0
votes
0answers
12 views
Bash script not passing variable through ssh [duplicate]
I'm trying to write a script that will ssh into multiple servers and echo the line user_pref("plugin.state.java",2) into every user's firefox pref.js file. I keep getting the error
bash: ...
-1
votes
0answers
29 views
Bash script not quite working
First of all I am new to scripting / programming of any kind so have very basic understanding. I found this script and it does what I want it to do, except at the end I can't send the variable $msg to ...
2
votes
1answer
25 views
Change password with kpasswd via command line?
I want to use kpasswd to change my password. Since I have to do it for multiple realms, I'd like to automate it passing on the password. I want to set a variable in bash and pass that on to kpasswd, ...
1
vote
1answer
40 views
Add trailing slash in bash completion of directory symbolic links
I have a symbolic link for a directory,
e.g ln -s /tmp /xxx
Now when I type /xx and press tab key, bash would complete the line to /xxx
If I press it again it become /xxx/
Now, how can I ask bash ...
1
vote
0answers
19 views
pmap hangs on OOM process
I did attempt a search, but there doesn't appear to be much out there on pmap so here goes.
I have a script that works with WebLogic instances to gather data on them which we can send to our Devs for ...
0
votes
1answer
34 views
SSH into another VM via Perl / Sh script failing. Works manually
I want to run a Perl CGI script (a_web_page.cgi) from my dev box .1.20 that runs a bash script from the same folder (host_script.sh).
This script then runs a SSH command to another server 1.10 that ...
1
vote
2answers
40 views
Can someone clarify for me about the global variable in this shell script?
Here's the code.
#!/bin/bash
var_change() {
local var1='local 1'
echo Inside function: var1 is $var1 : var2 is $var2
var1='changed again'
var2='2 changed again'
}
var1='global 1'
var2='global ...
0
votes
1answer
26 views
I moved a new program into my bin folder, but nothing happens when I try to run it [on hold]
I have two identical files in my ~/bin folder, test and test2. Both just print a string. One works; the other, which I just put in there today, doesn't. In fact nothing happens at all, which is odd. ...
-1
votes
1answer
26 views
negation equivalence
I have this exercise:
Write a script, which uses if-then-else-fi and accept sequence of parameters -a and -b with values "true" and "false", while for every pair writes negation of expression -a ...
0
votes
1answer
18 views
How do you handle multiple validation rules on varied user input?
I'm using a Bash script to prompt users for several variables before continuing. If I want to create static validation rules and execute them on user inputs in an "a la carte" fashion, how would I go ...
2
votes
1answer
36 views
Iterating over multiple-line string stored in variable
I read that it is bad to write things like for line in $(command), the correct way seem to be instead:
command | while IFS= read -r line; do echo $line; done
This works great. But what if what I ...
0
votes
2answers
31 views
Will the stdout output of a background process be taken as the stdin input of the foreground process?
When a background process outputs to stdout to appear on terminal, will the output be taken as stdin input to the foreground process?
Note that the background and foreground process are not related by ...
0
votes
0answers
14 views
Utility for managing and defining prompt definitions
Due to escape sequences, prompt definitions often have dyslexia-inducing complexity. For example, here is one person's definition:
ORIG=$PS1
PS1="\[${txtund}${green}\]LOCAL\[\[${reset}\]";
...
6
votes
3answers
1k views
Meaning of `10#N`
Jimmij wrote:
I would probably end up using temporary directory in this case:
for file in [[:digit:]]*.png; do
echo mv $file tmp/$(printf %04d $((10#${file%.png}+1))).png
done
The ...
2
votes
2answers
259 views
How do I automate to display cursor under the prompt on shell
I run following series of commands to bring curser under the prompt on shell terminal.
$ NL=' # << press enter
' # << press enter again
$ PS1=${PS1}${NL}
...
0
votes
1answer
35 views
Problem using head to remove last line of file [duplicate]
I was recently looking for a way to remove the last line of a file foo.txt and came across the following solution
head -n -1 foo.txt temp.txt; mv temp.txt foo.txt
which works fine. However, I ...
13
votes
3answers
2k views
What does ${1:0:2} mean in this context?
I am looking into the code displayed below and it checks the input if the row/column arguments start with either -r or -c.
What does ${1:0:2} mean in this context?
rowArgName="-r"
colArgName="-c"
...
-1
votes
0answers
34 views
Bash hangs on sourcing scripts [on hold]
At first I noticed the problem when my shell hung on starting. If I press Ctrl+C as soon as the terminal opens, it goes to a normal prompt and things defined in my ~/.bashrc work.
So I did:
mv ...
0
votes
1answer
26 views
How can I get my bash script to remove the first n and last n lines from a variable?
I'm making a script to preform "dig ns google.com" and cut off the all of the result except for the answers section.
So far I have:
#!/bin/bash
echo -n "Please enter the domain: "
read d
echo "You ...
0
votes
2answers
35 views
How is redirection implemented?
Is redirection a concept of the shell, not of the OS kernel?
How is redirection implemented in terms of system calls?
Is redirection implemented similarly to pipe?
0
votes
3answers
40 views
find -exec ls -lR {} \; returns every item twice
Background: I'm currently writing an archiving script, which creates gzipped tarballs from some folders and their contents. It should be able to synchronize the gzipped archives with the sources ...