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

Why the output is not written to log from expect shell script

I am trying to write the output of the netcat command including the command also to a file by logging into remote servers. But it is not writing. What am i missing ? #!/usr/bin/expect -f set user ...
0
votes
0answers
18 views

bash command to simply print new bash commandline like [tom@cerulean ~]$ [on hold]

My shell script used carriage return '\r' to erase my current [tom@cerulean ~]$ bash line to print an information (that is run asynchronously then returned when done). I want something that will to ...
0
votes
1answer
16 views

cron: output of a script?

I've got a cronjob that looks like this 0 0 * * 7 [ $(date +\%d) -le 07 ] && /home/archiver/archiver.sh &> /home/archiver/output And it works from the cron+bash perspective in that ...
1
vote
1answer
30 views

When did bash quit exporting SHELL?

I upgraded a Debian box from stable to Jessie and I noticed that SHELL is no longer exported, so screen and similar programs start dash for subshells instead of bash. When was this change made and ...
2
votes
2answers
42 views

How do I swap the two last command line arguments?

$ ln -s ./dir/target.txt /path/to/source.txt{cursor here} How do swap file typed filenames in command line? Alt+T swaps words, not filenames, resulting in ln -s ./dir/target.txt /path/to/txt.source. ...
5
votes
4answers
244 views

Spaces next to pipes

I've seen history | grep blah and history |grep blah; and history|grep blah also works, though no one ever seems to use it. Is there any significance in the spaces (e.g. piping to/from different ...
0
votes
2answers
22 views

use backquotes in a script [on hold]

Why this difference between echo $Date and echo "$(date +%s_%kh%M_le_%a_%d_%b_%Y)"? beginning=$(date +%s) diff="0" rest="$1" tmp="0" now="0" Date=`date +%s_%kh%M_le_%a_%d_%b_%Y` echo -n "$1" while [ ...
0
votes
2answers
30 views

Gzip file but excluding some directories|files and also append current date

I'm looking for a way to create a .tar.gz file from a directory but I have some doubts. I'm know that the command for create the file is: tar -zcvf /path/to/compressed/file.tar.gz /path/to/compress ...
3
votes
1answer
47 views

How to swap two commands in bash?

Say I have command A and command B but I want B to run when I type A and vice versa. I've tried alias A='B' alias B='A' But this doesn't seem to work for some reason. How do I do this? EDIT: ...
3
votes
1answer
23 views

How to sort an associative array and retain the keys?

I have an array with filenames as keys and a numerical value as values. MYARRAY[00001.jpg] = 31 MYARRAY[00002.jpg] = 200 MYARRAY[00003.jpg] = 98 I need to sort them so they are ordered by value. ...
1
vote
0answers
37 views

Bash cannot see PATH update

I am running Debian on a VM. I login to the GUI and go to Applications > Accessories > Terminal. # echo shell: /bin/bash I modified ENV_SUPATH, ENV_PATH inside of /etc/login.defs. I restarted ...
1
vote
2answers
21 views

Does X mangle prompt environment variables?

I'm starting it with startx. Before that I have PS1 in my environment: $ cat /proc/self/environ | tr '\0' '\n' | egrep '^PS' PS1=[\u@\H \w] PS3=> PS2=> PS4=+ From inside X I get: $ cat ...
1
vote
1answer
19 views

Why did a recent Ubuntu 14.04 update mess up my PS1 prompt?

I recently updated my Ubuntu 14.04 using the software update. This caused some problems. Initially I couldn't open up a new terminal window due to unknown errors with my .bashrc I had to use ...
0
votes
2answers
24 views

When is /etc/bash.bashrc invoked?

What is this file anyway? Documentation makes no mention of it. And it's not supposed to be run automatically (version 4.3, 2 February 2014): Invoked as an interactive login shell, or with --login ...
3
votes
1answer
38 views

How to append MD5 checksum of email content in bash?

I found some lines of output missing from an auto-generated email notification that was dispatched via cron. Having confirmed that there is no AVC error, I want to find out if the integrity of my ...
3
votes
3answers
71 views

spawn - command not found!

I am using Mac OS X 10.9.4, following is my script to copy files from local machine to different host #!/bin/bash #!/usr/bin/expect echo "I will fail if you give junk values!!" echo " " echo "Enter ...
2
votes
1answer
44 views

Test if postfix is running

I'm searching for a reliable way to test if postfix is running from inside a bash script. My first attempt was simply trying pidof postfix, which doesn't work. Then I tried to get the postfix ...
1
vote
1answer
78 views

Swap two files in bash [duplicate]

How do I swap two files in Linux console with minimum typing? Boring approach: $ mv file1.dat fileX.dat $ mv file2.dat file1.dat $ mv fileX.dat file2.dat
3
votes
2answers
59 views

Use lines in a file to produce string and file name

I have a file, foo.txt, that has a folder name on each line: folder_1 folder_2 folder_3 And I'd like to do something like this: cat foo.txt | xargs -I {} echo 'function {}() { return stuff; }' ...
0
votes
1answer
31 views

How does `ls` know whether it's piped or printed [duplicate]

ls normally prints like this: 1 1249 1653 23 33 4581 6202 6447 789 836 903 config.gz kpageflags sysrq-trigger 10 1253 1658 24 34 4582 6206 648 79 837 ...
0
votes
1answer
36 views

Why does the input to xargs is 1 string but without is strings in separate line?

I am trying to pipe file to rm via xargs. I understand that what I am tryng to do could be done by git clean but I am practicing the cli. I tried this: for files in $(git status --porcelain| sed ...
0
votes
1answer
15 views

Values from two lists are not processing correctly within two nested loops

I am trying to pass some values contained in two lists to a simple echo within two nested for loops (the echo is used to look at what is generated inside the inner loop). But the results are not ...
1
vote
3answers
37 views

How do I use inserted values using getopts

I have this bash code combined with getopts and if I understood getopts correctly OPTIND contains the index of the next command line option and all the command line options provided to shell script ...
-1
votes
1answer
24 views

using the sed command in bash show output in a new text file? [on hold]

Hey everyone I am new to the world of UNIX/Linux.My professor wants my class to use sed command to display output in a new text file but did not give us the commands; any help would be useful thanks
0
votes
0answers
16 views

Using a custom script for cron jobs mail notification

After coming across Mailgun I would like to write my own script to use their API in order to send mail notifications from cron jobs — avoiding in this manner having to worry about installing a ...
1
vote
3answers
46 views

Traverse all subdirectories in and do something in Unix shell script

I am new to bash scripting. I am working on a shell script and got stuck from last 3 days. I want my shell script to visit all subdirectories in a main directory. Do something in directories, sent ...
0
votes
0answers
28 views

Unrecoginzed option: using 'getopt' cmd in shell script [on hold]

What is wrong in the command: if ! options=$(getopt -n myscript -l a:,b:,cc:,dd:,ee:,ff:,gg:,hh: -- "$@"); then exit 1; fi I get an error msg: mhagent: unrecognized option '--hh' options=' --aa ...
1
vote
1answer
26 views

if command in find -exec

I was just trying to list all directories and files under current directory and also write if they are file or directory with the following command: find -exec echo `echo {} : ;if [ -f {} ]; then ...
1
vote
2answers
43 views

Extracting numbers with a decimal point from ls output in Bash

I would like to extract the numeric part of the file names that begin with "hsli" and end with ".h5" in Bash on Ubuntu 14.04.1 64-bit LTS. My ls -l hsli* output is as follows: -rwxrwxrwx 1 ongun ...
0
votes
2answers
28 views

What I am doing wrong with this bash variable? [on hold]

How can I insert a variable into a command? In the case below, I need to concatenate the command with the variable file name. #!/bin/bash # Define a timestamp function timestamp() { date +"%D-%T" ...
1
vote
1answer
33 views

How can I get $PATH to always include $(pwd)/sub_directory/.bin

If the path ~/dev/project1/node_modules/.bin/ionic exists, and my working directory is ~/dev/project1, I would like to be able to just type ionic and hit enter. I could include all those ...
-5
votes
1answer
25 views

Remove characters from string with sed [on hold]

I have this header: >tr|G3Q381|G3Q381_GASAC Uncharacterized protein OS=Gasterosteus aculeatus PE=4 SV=1 and I was thankfully helped on here to get it to: >G3Q381_GASAC but now I need to ...
2
votes
1answer
20 views

Show shell greeter only on initial login

Is there any way to show a greeter (motd kind of thing) only on initial login, and not when you do sudo su? Here's my current .bashrc: #!/bin/bash # # ~/.bashrc # # If not running interactively, ...
0
votes
0answers
12 views

PHP execute find + cp from page

I would like to copy some files from one folder to another in a Linux system through the use of PHP's methods exec or shell_exec. Currently, the bash shell executes this line correctly and the files ...
0
votes
1answer
35 views

Detecting function circular references in bash

Why does the following idiom not work in bash 4.1.0? if [[ "${FUNCNAME[*]:1/$FUNCNAME/}" != "${FUNCNAME[*]:1}" ]] Here it is in context... function isCircularRef_test () { # ### Seems like ...
-1
votes
0answers
41 views

replace first string before first space [on hold]

how to replace first string before first space? NC_009925.1_13653 [754389 - 754574] Acaryochloris marina ATTCCTGATTCTCTTGATGAAAGTAACATTATGGATCAT... TATGATCCATTCAGGCATGATGCAAGGCGCTACCCCCAA... 110311 ...
0
votes
0answers
6 views

Specify “any sequence of digits” to ‘compgen’

How can I get compgen to return matches for “any valid sequence of digits”? The Bash compgen command is used to generate completion matches in Bash programmable completion. There are many options for ...
1
vote
1answer
47 views

getopts passing value of declared parameter to function

I have function port.sh as stand alone script and i'm wondering if is possible to put this function in the same script where getopts is and pass value of OPT_B into function and get output of it? ...
0
votes
3answers
43 views

Parent script continues when child exits with non-zero exit code [on hold]

I have a script that calls another script. When the child script fails, I'd like the parent to fail as well. In the child script child_1.sh, I have something like this: if [ $SOME_BAD_CONDITION ] ; ...
1
vote
1answer
39 views

cp with interactive don't prompt before overwrite

I observed a strange behavior cp. Exactly the point is that cp did not ask me for confirmation, even with the option interactive. A test case looks like this Existing files find * -type f ...
1
vote
3answers
67 views

How can I make sudo forget the password automatically after one command?

My problem is the following: I want to edit a file that is only readable by root. That's why I use sudo vim ~/thefile I could type sudo -K after exiting vim, but I was hoping that there's an ...
3
votes
1answer
35 views

Question about interactive detection in bash

I have a question about interactive detection in bash. The following script prints if it is called in interactive mode or not. $ cat int.sh #!/bin/bash if [ -t 0 ]; then echo "interactive" ...
4
votes
2answers
227 views

Delete files older than specific file

I need to delete from a folder all files older than a specific file. Running bash on CentOS 7. I have a solution for this, but I think there should be a more elegant way do it: ...
1
vote
2answers
42 views

print the output of 2 commands in 1 file on the same line

Thanks for looking at this. I have a possible simple question, but I wasn't able to find any help so far on the internet. I have a script that has mainly 2 commands that process output. But both ...
1
vote
2answers
65 views

Search for matching files with wildcards without using find in a bash script

For an assignment, I'm supposed to write a bash script that can act as a very basic find, but without actually using the find command. For example, if I put in this input: my_find ~/homedir/ -name ...
7
votes
4answers
188 views

Matching and pasting to line

So I have 2 very big text files, consisting of lines like so: First: Robert:Dillain:Other:Other:Other Julian:Brude:Other:Other:Other Megan:Flikk:Other:Other:Other Samantha:Minot:Other:Other:Other ...
0
votes
1answer
29 views

How can I multiply a column by a variable and write out? [duplicate]

I would like to multiply a single column in a .txt file by a variable and then write to another .txt file. What am I missing from the awk line? Appreciate any help in advance. !/bin/bash ...
2
votes
1answer
35 views

Can we use two brace expansions together?

For example, I want to rename a file abc to bd. Why doesn't two brace expansions work? How shall I make brace expansion work in my example? Thanks. $ touch abc $ mv {a,}b{c,d} mv: target `bd' is not ...
6
votes
7answers
2k views

Is there a unix command that gives the maximum of two numbers?

I was looking for a command to limit numbers read in from stdin. I wrote a little script for that purpose (critique is welcome), but I was wondering if there was not a standard command for this, ...
1
vote
0answers
33 views

How do you derive a decimal from a math operation involving a variable?

I'm trying to find derive SCALEFACTOR which is basically 10000/(sum of 4th column in a file). How do I get a decimal from the output? Appreciate any help in advance. #!/bin/bash ...