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

0
votes
2answers
30 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 ...
3
votes
0answers
20 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
1answer
120 views

have I found a bug in BASH? [closed]

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
58 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 ...
4
votes
5answers
61 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
34 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
35 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
33 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 ...
3
votes
1answer
29 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
49 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
24 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
40 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
41 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 [closed]

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
31 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
19 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
41 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
38 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
16 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
268 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
36 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 ...
15
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" ...
0
votes
1answer
31 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
41 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
190 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 ...
0
votes
2answers
60 views

Unable to execute bash script inside expect script

i have a expect script like #!/usr/bin/expect ..... spawn passwd expect "password:" send "password" .... .... .... ~/test.sh Wile executing this, I'm unable to run bash script test.sh. How to ...
0
votes
1answer
27 views

Change a file while redirecting it as stdin input to a command

In Bash, while running mycommand < myfile, I modify myfile's content. What content of myfile does mycommand get? Does mycommand get the original content of myfile when i started running it, or ...
-1
votes
1answer
39 views

How to specify a compound command as an argument to another command?

Suppose command1 takes another command (say command2) as argument, with command2's arguments as the remaining arguments of comman1, i.e. command1 command2 arg... When command2 is a made up of ...
-1
votes
2answers
37 views

Command passed as an argument to another command is not found in PATH

Generally when a command appears as an argument to another command e.g. command1 command2 how is command2's executable searched for? Is it searched in $PATH? Is it specific to how command1 ...
0
votes
2answers
49 views

How can I convert all the html files I get into text files after a wget command?

How can I convert all the html files I get into plain text files after a wget command? I'm thinking of using lynx to convert html files into ".txt" files, getting rid of tags. I have this snippet ...
0
votes
1answer
38 views

practice linux for practical use [closed]

I have learned and studied linux for 6 months with books like 'The linux commandline'. But, I'm just student, not a business man. When I study linux and do not use it for long time, I always forget ...
1
vote
3answers
69 views

Using grep in conditional statement in bash

I'm still very new to scripting in bash, and just trying a few what I thought would be basic things. I want to run DDNS that updates from the my server running Ubuntu 14.04. Borrowing some code from ...
1
vote
1answer
34 views

Awk field printing within the ternary operator

If you're familiar with DISA STIGs, the test for RHEL-06-000518 is /bin/rpm -Va 2>/dev/null \ | /bin/grep '^.M' What I want to do is pull just the file name out of that test, and make pretty ...
0
votes
1answer
50 views

`ssh` fails to reach destination

I am trying to ssh to another machine in my lab using the IP address. The IP address is 137.84.4.211 and let's say the host name is MyName. My IP address is 137.82.81.10. I don't know if this mean two ...
0
votes
0answers
21 views

How to generate following output file by using PBS script language?

I need to run interacting job with such specifications by using PBS on the cluster. This job must write the output file, in which there is following information (I have not specify this in the .pbs ...
1
vote
1answer
26 views

How to express floating point expressions in bash scripts

Why does a2=100. echo 1.1*$a2|bc work on the terminal, but the 3 variants in the following script don't: a2=100. echo " 1.1*$a2|bc $(1.1*$a2|bc) $((1.1*$a2|bc)) ">x.sh
2
votes
2answers
57 views

find and replace double bracket values

I have a requirement to replace the [[KEY]] in double brackets in one of the html file with VALUE. Key values are available in different files. After replacement, I need to put output in separate ...
0
votes
1answer
25 views

Determining Domain Base Name from Nslookup Results [closed]

I am trying to search all IP addresses that connected to my server and want to find abusive servers from nslookup results. nslookup 31.204.150.10 | grep "in-addr" Some example results: ...
-1
votes
3answers
42 views

In a bash shell script , how to write a loop that goes trough three values [duplicate]

I'm trying to write a shell script using bash for the following problem: Write a loop to go through three values (A B C) and displays each of these values to the screen (hint use a ‘for’ loop). ...
26
votes
4answers
2k views

Is there any way to execute commands from history?

For example: [root@ip-10-0-7-125 ~]# history | grep free 594 free -m 634 free -m | xargs | awk '{print "free/total memory" $17 " / " $ 8}' 635 free -m 636 free -m | xargs | awk '{print ...
1
vote
1answer
29 views

Meaning of the bash shortcut Alt+{

What's the meaning of the output from the Bash shortcut Esc { (Esc, Shift+[ on a US keyboard)? e.g., $ ls brown.txt file1.txt file2.txt fox.txt quick.txt Esc { produces the following at the ...
1
vote
1answer
28 views

Remove certain types of files except in a folder

I have a command in my makefile for clean: rm -rf */*.o */*.cmo */*.cmi */*.cmx */*.cma */*.cmxa */*.annot Now I would like to write a cleanpartial that removes these files except those in the ...
0
votes
2answers
44 views

Saving Output In a Variable and Re-using it

page=`grep $x /var/www/vhosts/example.com/statistics/logs/access_log | awk '{print $7}'| sort |uniq -c |sort -nr` times=`$page | wc -l` I am trying to save output of grep in a variable as page. But ...
1
vote
2answers
77 views

Why is this script looping on the first line of the txt file?

#!/bin/bash usernameFile="/home/netadmin/username_list.txt" logFile="/var/log/netvpn-mag-archive/netvpn-mag-20160" while read -r line < $usernameFile; do if [[ "$line" != " " ]]; then ...
0
votes
1answer
35 views

Conditions sent over ssh are performed locally, not remotely [duplicate]

So I am trying to do something like this: ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i \ /home/backupboy/.ssh/id_rsa user@server.com \ "[[ $(ls -1 /mnt/dir | wc -l) -gt 4 ...
0
votes
3answers
32 views

Accessing Secondary Variables

for x in `cat /var/www/vhosts/example.com/statistics/logs/access_log.processed | awk '{print $1}' | sort | uniq -c | sort -nr | awk {'if ($1 > 2000) print $2'}`; do #Works printf ...
2
votes
1answer
22 views

Connect via telnet and doing certain operations

I'm trying to code a script where I can connect via telnet to another server and execute certain operations, but I'm having problems with the result of this process. The objective is to connect to a ...