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
1answer
11 views

Swap two files in bash

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
2
votes
1answer
15 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
25 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
0answers
18 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
14 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 ...
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
3answers
31 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
vote
2answers
60 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 ...
1
vote
3answers
44 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 ...
-1
votes
1answer
23 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
2
votes
3answers
467 views

When I try to run a comment I get the error `The command could not be located because '/usr/bin' is not included in the PATH environment variable'

when I try to run in the terminal, I get the error The command could not be located because '/usr/bin' is not included in the PATH environment variable. e..g. jeper@jeper:~$ clear Command 'clear' is ...
0
votes
0answers
7 views

GNU screen init script, /dev/pts device wrong ownership

I have this very lazy init script to start GNU screen as the user john on my system. The purpose of it is to start screen on boot and send a newline character to it. It runs on a Raspberry Pi which ...
0
votes
0answers
12 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 ...
0
votes
0answers
26 views

getting ? in permissions when running ll/ls command

I am trying to remove a folder and I am getting rm: cannot remove ‘...' when running the ll command I am getting : > ll ./folder/ ls: cannot access ./folder: Input/output error total 64 ...
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, ...
7
votes
4answers
175 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 ...
20
votes
1answer
4k views

Execute bash scripts on entering a directory

What is the best way to execute a script when entering into a directory? When I move into a new directory I would like bash to execute the projectSettings.bash script much like RVM does.
1
vote
1answer
27 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 ...
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 ...
1
vote
1answer
22 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 ...
0
votes
3answers
110 views

Determining the exit status of the “return” built-in

I was reading about traps, but only return works for me in my shell script, so was wondering what status or code it returns, so what I tried is, #!/bin/bash seeOutput=`return` echo $seeOutput It's ...
0
votes
2answers
27 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
45 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? ...
2
votes
2answers
4k views

Print line numbers of files I am searching through [closed]

I am looking for a way to print the line number of files my script is going through. I have found $LINENO but when I do echo 'Found foo in file' $(basename $foo) 'on line' $LINENO >> foo.csv ...
-5
votes
1answer
24 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 ...
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
2answers
163 views

How to load .bashrc from “bash -c”

Trying to run a function defined in my .bashrc using "bash -c ". I end up with the error "command not found". How do I get "bash -c" to load my init file?
0
votes
1answer
29 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 ...
2
votes
1answer
19 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 ...
-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 ...
2
votes
2answers
4k views

grep output of expect script

I'm trying to run some expect language, and grep/parse the output all in one script. I want to grep the output of and look for "error" (I should note that standard linux commands like awk, sed, grep, ...
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
38 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 ...
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" ...
1
vote
2answers
41 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
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 ...
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 ...
3
votes
3answers
54 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
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 ...
8
votes
3answers
657 views

Escape sequences in output of script called from ncurses application

I'm currently running mcabber as my Jabber client (which uses ncurses) in a tmux session on my homeserver. Locally i run iTerm2 as a terminal emulator, which supports the triggering of growl ...
3
votes
2answers
90 views

BASH: Special character '�' suddenly appeared (Ubuntu)

When I erroneously type 'ñ' (expecting to type any command) and then remove it and type the correct letter, the output returns the command with a special character attached �, obviously the shell ...
4
votes
2answers
225 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
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 ...
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 ...
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 ...
11
votes
2answers
12k views

“su” with error “X11 connection rejected because of wrong authentication.”

As root, I'm connecting to a remote host to execute a command. Only "standarduser" has the appropriate id-file and correct .ssh/config, so I'm switching the user first: su standarduser -c 'ssh -x ...
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?
1
vote
3answers
51 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 > ...
1
vote
1answer
24 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 ...