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
0answers
13 views

Mass rename numbered extensions? [duplicate]

I have several files in the format of: download.1 download.2 download.3 ... I'd like to rename all these in the following format: download1.exe download2.exe download3.exe Is there an easy way to ...
1
vote
0answers
6 views

How to adjust this little script from ipv4 to ipv6?

This script is checking who is knocking on the phone line and displays the address by whois of the person who wanted to knock on the phone line. awk '{ for (i = 1; i <= NF; i++) if ($i ...
0
votes
3answers
63 views

bash script to cd into directory

This bash file running on Mac terminal failed to change the directory. Rather reporting it does not exist when it actually does. Any thing I did wrong? #!/usr/bin/env bash set -e read name ...
1
vote
1answer
28 views

CRON job that kills a process started by previous CRON

I need to create a cron job that runs a bash script in background which does not end unless killed. The bash starts a process that should keep running for about 28 hours then I need another cron job ...
4
votes
1answer
224 views

changing user home directory has no effect

When I switch from root user to a user (automatically created when installing git-auto-deploy) with sudo -u git-auto-deploy /bin/bash I always get this error: bash: /root/.bashrc: Permission ...
5
votes
3answers
242 views

How to prevent word splitting without preventing empty string removal?

I need to pass as a program argument a parameter expansion. The expansion results in a filename with spaces. Therefore, I double-quote it to have the filename as a single word: "$var". As long as $...
3
votes
1answer
41 views

trap on command exit not working unless used in a function or sub-shell

Am experimenting a bit with trap on invalid command return code using a sample code #!/bin/bash # Exit on error trap 'echo 'exiting..';exit' ERR set -e h=1 b=$((h+)) # <----- command causing ...
2
votes
0answers
26 views

BASH script to monitor subprocess and throttle it for CPU temperature control

I am looking for hidden traps I may have set in my code (listed at the bottom), and for other things I have done incorrectly. Since the main functionality comes from two posts on this board, it only ...
3
votes
4answers
69 views

Bash: Path or link to a line in a file?

/path/to/fname#line1242 Is there a way to refer to a specific line number in a file as part of the pathname, or some way to package a link to a line number, which looks/behaves like a pathname? For ...
1
vote
1answer
43 views

Can I safely ignore: “warning: command substitution: ignored null byte in input”?

Is it possible to safely ignore the aforementioned error message? Or is it possible to remove the null byte? I tried removing it with tr but I still get the same error message. this is my script: #!/...
1
vote
3answers
62 views

one simple little “cd” doesn't work in script [duplicate]

#!/bin/bash # echo $PWD cd /home/<my username>/<long path> echo $PWD What I get when executing it with bash script.sh: /home/<my username> : No such file or directorye/<my ...
1
vote
2answers
31 views

properly using the $ atom in a parameter substitution

I'm trying to perform a parameter substitution that strips everything from the first - char to the end of a string like so: v0.1-bla-hblah-232 -> v0.1 So I'm using the following script: #!/usr/...
0
votes
1answer
33 views

bash: redirect stderr to file and stdout + stderr to screen

I would like to save the stderr stream of a command into a log file but I also want to display the whole output (stdout + stderr) on the screen. How can I do this? I only found the solution to ...
3
votes
2answers
37 views

How to list the open file descriptors (and the files they refer to) in my current bash session

I am running in an interactive bash session. I have created some file descriptors, using exec, and I would like to list what is the current status of my bash session. Is there a way to list the ...
0
votes
1answer
25 views

Amigados assign command in linux bash

AmigaOS allow[ed|s] to do an assign a path to a short handle. For example FONTS: can point to DH0:System/fonts. Then you can refer all the times to FONTS: like cd FONTS: , ls FONTS: and so on. In ...
1
vote
1answer
32 views

Using input from two different files in a for loop

I have a list of files that I want to search across a list of database tables: [root@host hs]# head -n 3 tables rec_playinth120116 rec_playinth120216 rec_playinth120316 [root@host hs]# head -n 3 ...
-1
votes
2answers
53 views

bash script to identify the files based on current date and file name pattern

bash script to identify the files based on current date and file name pattern . There are 10 files located in different directory which contains date pattern in it . I need to pick these files one by ...
-3
votes
1answer
36 views

Egrep command not working- winbash [on hold]

I have win-bash installed on my windows 10 PC, and every time, when I'm trying to use the egrep command (or grep -e), with regex, it is not returning an error, but it still not working. I'm using the ...
0
votes
0answers
26 views

SSH over multiple servers and get the output by executing each command

I have a script to get server health from multiple servers like this: #!/bin/bash for ip do ssh 192.168.1.209 ssh root@$ip cat /proc/loadavg | awk '{print $1}' #CPU Usage free | grep Mem | ...
0
votes
1answer
28 views

Terminal Startup Scripts?

I recently downloaded Ruby onto my mac via rbenv, and I read instructions that showed me how to start up rbenv every time I open terminal. Is there a way to view all the startup scripts for terminal? ...
0
votes
1answer
28 views

“. <file>” syntax vs. “source <file>” [duplicate]

In my .bashrc file are these lines if [ -f ~/.bash_aliases ]; then . ~/.bash_aliases fi I know that . <file> syntax is very popular...what is it doing exactly? How might this be different ...
5
votes
3answers
151 views

Generate and move thumbnails recursively

I want a bash script which does the following: Find pictures (jpg,jpeg,JPG,JPEG) recursively from current directory downwards Generate a thumbnail with imagemagick's convert Move thumbnail to other ...
5
votes
1answer
42 views

Assign file name to a variable using pathname expansion

Is there a reliable way to assign a file name to a variable taking advantage of pathname expansion? This works but looks kind of dodgy: the_file="$(echo ~/downloads/stack-*-linux-x86_64-static.tar....
0
votes
2answers
34 views

Replace string in a file from bash script value

This bash script runs on a Mac terminal, it needs to ask the user for input $name, then replace a string in another file to include the user input PLACEHOLDER_BACKEND_NAME=$name. #!/bin/bash read -r ...
0
votes
0answers
24 views

Problem with booting into a user-level Bash Shell instead of the root user on Windows 10

I have a /home/user account but when I boot into Bash I boot into the root user. I have to su user to get into user. How can I boot into Bash and go directly into the user account and not root. ...
5
votes
2answers
158 views

How to insert variables inside a string containing “”?

I want to construct an xml string by inserinting variables: str1="Hello" str2="world" xml='<?xml version="1.0" encoding="iso-8859-1"?><tag1>$str1</tag1><tag2>$str2</tag2&...
15
votes
3answers
1k views

Is it always safe to use `eval echo`?

Using eval is often discouraged because it allows execution of arbitrary code. However, if we use eval echo, then it looks like the rest of the string will become arguments of echo so it should be ...
5
votes
2answers
62 views

How to set PATH when running a ssh command?

Assuming user has /bin/bash as the shell in /etc/passwd. Then ssh user@host command runs the command using Bash. However, that shell is neither login nor interactive, which means neither ~/....
17
votes
2answers
443 views

Why does remote Bash source .bash_profile instead of .bashrc

Bash Manual says: Bash attempts to determine when it is being run with its standard input connected to a network connection, as when executed by the remote shell daemon, usually rshd, or the secure ...
0
votes
1answer
68 views

What's wrong with `if ($num1 -eq 0) || ($num2 -eq 0)` in a bash shell script?

My code: #!/bin/bash read num1 read num2 if ($num1 -eq 0) || ($num2 -eq 0) then exit else echo "$(($num1+$num2))" echo "$(($num1-$num2))" echo "$(($num1*$num2))" echo "$(($num1/$num2))" fi ...
0
votes
2answers
64 views

How to run program from bash shell without it running in the process of shell

If you run say Nemo from bash shell, you're not going to be able to execute any other commands from that shell until you end the Nemo process. And that's my problem. I want to be able to run other ...
0
votes
3answers
34 views

alias with sudo not working [duplicate]

I'm trying to add an alias to my .bashrc alias oops='sudo !!' when i execute it however I get: sudo: !!: command not found eliminating the alias from the .bashrc and im able to manually use sudo !!,...
1
vote
2answers
34 views

How can I wrap a complex command with a shell script?

I'm using optirun from bumblebee. It is designed to start my 2nd GPU, run the command given, and shut down the 2nd GPU at the end. A simplified example: optirun echo test | cat However there's a ...
1
vote
1answer
65 views

Solved - How to avoid “bash: q: command not found” everytime I 'su'?

Everytime I su from root to another user on a centos, it displays bash: q: command not found" before to give me the prompt. How to fix this? Should I comment line Defaults secure_path = /...
1
vote
0answers
16 views

Does `csh` have the Bash equivalent of `set -o nounset`?

I have some legacy csh code that is having issues and I think the issue is related to unset environment variables that need to be set but aren't being set. Does csh have the Bash feature set -o ...
0
votes
2answers
44 views

Store variable from output bash

Got a bash script to create a backup of some files, it is set in Cron. The bash command, including output, is: [vagrant@localCentOS71 ~]$ sudo create_backup.sh Check if all is good ... done Doing it ...
0
votes
0answers
63 views

Command work on Terminal but not in ssh

I have installed some external programs on Linux. I can execute this in the terminal shell : 'myProgram ' but, in ssh mode, it says it cannot recognize it.... Message is : ' bash: jupyter: ...
1
vote
2answers
57 views

move subshell output into an array in bash 3

How do I import the results of a subshell command into an array in bash 3? I have been using mapfile to accomplish this in bash 4 as follows: mapfile -t myarray < <(someScript.sh) However, ...
1
vote
0answers
27 views

List commands in a shell's history in the order of their termination times?

In a bash shell, history will list commands in the order of starting time. Can I list commands in the order of terminating time? One possible application is that it will help to retrieve those ...
3
votes
3answers
42 views

Replace character with alphabet depending on position in string

I have an output like this: (2+05:10) (10:19) (00:45) This output represents day hours and minute. I would like to replace the ':' with 'd','h' and 'm' respectively, to get this 2d05h10m 10h19m ...
0
votes
3answers
30 views

how to get bash indexes of parameters array

i want indexes of parameters, and can get it by dummy var: dummy=( $@ ) echo ${!dummy[@]} but is there straight way to get them, something like $!@ ... not working $!* ... not working ... or ...
3
votes
2answers
39 views

Test for function's existence that can work on both bash and zsh?

Is there a way to test whether a shell function exists that will work both for bash and zsh?
0
votes
3answers
50 views

Echo commands and output to file from interactive shell [closed]

I am looking for a graceful way to have bash write both the command I executed, followed by the output of that command to a file from an interactive prompt. Such that running a command like this: $...
-6
votes
0answers
28 views

script to Send an email if latest file arrival is more than 4 Hours [duplicate]

I am new to Linux and I need your Help.I am lookup for a Linux script to check the latest file arrival time. If that latest file arrival time is more than 4 hours when compare to system time I need ...
0
votes
3answers
56 views

How to add comma after each column?

I need to do this so when I open the .csv in excel each column has its own tab. My text looks like this: smmsp Purpose - Service account for Sendmail; Owner - sysadmin; SERVICE ACCOUNT ...
1
vote
1answer
29 views

Executing commands from a process running under a nologin user

I have a process that runs under a nologin user (in this case Tomcat server). I would like to execute some shell commands from that process but most of them are not available apart from standard ...
1
vote
1answer
27 views

If statment trouble

I've written the following script: #!/bin/bash SINGLE=`cut -c 7-13 Data.txt` cd ../FASTA_SEC_EDITED/ for i in ${SINGLE}; do if [[ -r "${i}_Forward_Trimmed.fa" && -r ../REVERSE_COMP/"${...
1
vote
1answer
15 views

Compare path with user home and determine if first directory is “.nvm”

So I have this path as my present working directory: /home/oleg/.nvm/versions/node/v7.2.1/lib/node_modules Using a bash script, I want to determine if this directory is within my user home directory ...
12
votes
3answers
1k views

In the code “{ exec >/dev/null; } >/dev/null” what is happening under the hood?

When you redirect a command list that contains an exec redirection, the exec >/dev/null doesn't seem to still be applied afterwards, such as with: { exec >/dev/null; } >/dev/null; echo "Hi" "...
1
vote
0answers
34 views

STDERR redirection without intermediate file

Here is a toy shell script: #!/bin/bash set -e misspelled_command exec > run_$( date +%Y%m%d ).log 2>&1 echo "Logging" exit If I submit with nohup bash raise_errors.sh > /dev/null 2&...