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

Unrecoginzed option: using 'getopt' cmd in shell script

I'm new to shell and linux, it would be great if someone can help me find what is wrong in the command: command: if ! options=$(getopt -n myscript -l a:,b:,cc:,dd:,ee:,ff:,gg:,hh: -- "$@"); then ...
1
vote
1answer
18 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
41 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
23 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
22 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
23 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 ...
1
vote
1answer
18 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
11 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
27 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
40 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
35 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
42 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
37 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
65 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
34 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
219 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
38 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
1answer
41 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 ...
6
votes
4answers
165 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
28 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 ...
5
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
32 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 ...
1
vote
1answer
35 views

Why scripts run as user but not as a cron?

I have a script that checks to see if port 4000 is open and listening, if it is return true, else start a service that also outputs a logfile. The script runs fine if I execute it as a user, but if I ...
1
vote
2answers
40 views

How do I find folders containing no recently modified files?

I have a directory that gets a lot of data dumped into it, and I want to find all directories whose contents haven't been modified recently (e.g., in the last 5 days). I'm trying to compose a call to ...
3
votes
3answers
52 views

Is there any way to keep track of all the processes exec'd by bash

I'd like to be able to keep statistics on which programs I run the most through bash. Is there any way to insert some sort of hook into bash so that it logs everything it execs? Note that looking ...
1
vote
2answers
93 views

for loop when matching both front and back of file name

I'm trying to set up a for loop to run a process on pairs of files. The names of the files look like this 36_002_CGATGT_L001_R1_005.fastq.gz 36_002_CGATGT_L001_R2_005.fastq.gz ...
1
vote
2answers
14 views

Linux copy range of folders

I found this link with an example of how i can actually copy range of files Copy a range of files in command line (ZSH/BASH), using this $cp P10802[75-83].JPG ~/Images/. Is there any way i can also ...
1
vote
3answers
68 views

How do you parse through a subdirectory where the path contains spaces? [duplicate]

I'm trying to parse through a set of files in a directory on a mapped drive. However, I can't seem to resolve an issue that seems to be because of spaces in the path to the subdirectory. Would ...
0
votes
1answer
22 views

how to change several piece of html code

I have several chunks of html code ,see below, in a html page that I need to change Assurez-vous de bien recevoir tous nos messages en ajoutant bebeco@concretisezvosprojets.com à votre carnet ...
0
votes
2answers
30 views

A batch that cout the number of occurrences

I've to extract the number of words using each letter of the alphabet from A to Z. The script that i've to create create take as parameter the name of the dictionary file to analyze and will be used ...
-3
votes
0answers
23 views

How to configure the Shell if no .bashrc exist ?

I have a problem with my Xfce Terminal, once I start it it does not respond for a minute. I was told here to change settings in the .bashrc configuration file. Unfortunately no such file exist. What ...
1
vote
1answer
23 views

How do I control output after executing a command?

.. Script Run Complete. You have new mail in /var/spool/mail/<user-name> -bash-3.2$ I have seen the above message most the times on my prompt, probably while it's idle or as soon as script ...
1
vote
2answers
69 views

Is there any way to make scripts dynamic? [on hold]

I need my script to show the time till next run, continuously like a timer, is this possible?
-3
votes
0answers
20 views

How can I use multithreading in unix by considering its core's and cpu's? [on hold]

I actually designed a unix script for automate the backup and i used multithreading concept to make multiple gtar command to run simultaneously by getting the thread value in run time. My script is ...
1
vote
3answers
49 views

how to express line feed in shell?

Im my debian7.8 bash shell. str="deb http://ftp.cn.debian.org/debian/ wheezy main contrib non-free \n deb-src http://ftp.cn.debian.org/debian/ wheezy main contrib non-free " echo $str > ...
2
votes
1answer
49 views

Bash script to detect uploaded files triggers many times for one file

I have a simple bash script setup that uses the built-in inotify daemon running CentOS 6.6. The script will simply echo the file that is upload to a specific directory. The script works but it echos ...
0
votes
0answers
17 views

Possible to pass env vars into chpst without envdir?

I use runit to daemonize my web application, and I'm trying to see if I can have my process managed by sv not have to have a corresponding envdir for its environment variables. I wonder if I can just ...
3
votes
1answer
120 views

Can the command completion for `cd` be modfiied to only show directories and ignore files?

When I am in a directory in bash, and I press cd Space Tab, it shows everything in the directory as a possibility. (Show all 1000 possibilities?) This is really cumbersome when I am in a directory ...
0
votes
0answers
49 views

Bash script not executing when called from another start with “at command”

First, I understand this is probably something better suited for cron. However, I don't have access to cron. (shop rule around here) So, I am using the next best scheduling option at my disposal. ...
1
vote
1answer
15 views

Tmux - Get number of panes in the current window in bash variable?

I'm scripting Tmux, and would like to know the number of panes in the current window from a bash script. Is there anyway to find out this information? in pseudo code, i'd like something like this: ...
0
votes
1answer
20 views

tail-ing a filename that is a date [duplicate]

I am creating a logfile from kermit named the current date (which is in the format of DD MMM YYYY - which can not be changed AFAIK), and using the file name as today's date. I then have a Bash script ...
0
votes
2answers
53 views

help with bash scripting tput getting errors [on hold]

I am a beginner to bash scripting. I need help to figure out what is wrong with this tput menu. #!/bin/bash tput setb 3 tput clear function main_menu { option=0 until [ "$option" = "4" ]; do echo ...
0
votes
1answer
54 views

bash if, then and else statement

I am learning bash, I ran into a small problem when trying to write a small script #!/bin/bash clear read num if [ "$num" -eq 2 ] then [ -d "/etc/passwd" ] | sudo cp /etc/passwd /home echo ...
0
votes
1answer
26 views

how to list downloaded apt packages without dependecies

I'm trying to get the names of downloaded packages without dependencies.. I don't want to get all the files in /var/cache/apt/archives .. I only want to get the primary packages without dependencies I ...
2
votes
1answer
62 views

Bash - Split quoted parameters

I have a script which gets called with two parameters: ./script.sh a b I'm currently reading them through $1 and $2 (such as cd $1). My problem is that the output needs to be the same for when the ...
3
votes
3answers
168 views

How to match * with hidden files inside a directory

How to match the hidden files inside the given directories for example If I give the below command it's not giving the result of the hidden files, du -b maybehere*/* how to achieve this ...
2
votes
2answers
102 views

Bash menu with multiple parameters in one row

I have searched a couple of days and still didn't found the answer. I hope that you can point me in right direction. I would like to know how to write a bash script with a options, that can be ...
1
vote
1answer
59 views

bash $(printf “%s\n”) does not create multiline

I created shell script, that logs into FTP server and renames some directories. I put FTP commands in multiline string like so # !/bin/sh ftp -inv $HOST << EOF user $USER $PASSWORD $COMMANDS ...