Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [bash]

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.

-2
votes
3answers
42 views

Merge every second line from two files

File1: A B C D File2: E F G H How would I get Output: A BF C DH
4
votes
1answer
32 views

make bash exit if declare statement fails

tl;dr I want bash to automatically exit after declare var=$(false). My bash scripts use set -e. However, when using declare variable declaration idiom, the declare appears to "block" returning the ...
2
votes
0answers
15 views

When coding for Unix/Linux is it convention to use a trailing slash on path names, or to omit it?

When programming for Unix/Linux, is it best practice to use a trailing slash, or to omit it? For example: Trailing slash baseDir="/path/to/dir/" #code# outPath=${baseDir}addition/to/path/ No ...
3
votes
1answer
28 views

Test if any files that do not match a specific pattern exist in a directory

I am having much difficulty with this. I am trying to test if there exists files in a directory that DO NOT match a given pattern, returning true or false. In this case, files in $dir that don't ...
0
votes
0answers
35 views

How to stop bash script from running at login

The script below was executed and I can't find out how to stop it permanently. The script starts a few programs at login. script is saved in home/usr/audio-scripts and the script's name is ...
0
votes
0answers
34 views

Why does this rsync call not work properly?

I made a simple script to perform backup of my NAS. I do it as follows: date="$(date +%Y-%m-%d)" base="/backup" newest="$(ls -1td "$base"/*-*-*/ | head -n 1)" today="$base/$date" dirs="pub,data,...
1
vote
2answers
31 views

Passing options into man for a self-written help file

I have a question about the syntax of manpages. I just wrote documentation in manpage format for my little project. I would like to allow users to type man commandname option as in git ...
1
vote
0answers
28 views

Round Robin (RR) scheduling in Bash Unix Shellscript

I want to simulate CPU scheduling algorithms using Unix Shellscript but the loop in round-robin doesn't end when the shell script is executed. I can't figure out on how to fix the code. Here's the ...
5
votes
1answer
99 views

bash regexp matching fails in [[ ]]

I would like to check whether a user is in a certain group via [[ "$(getent group groupname)" =~ \busername\b ]] but this does not work (bash 5.0.3) although the following works: getent group ...
-1
votes
1answer
36 views

Bash substitution shows directory structure

I want to escape back quotes in a variable before writing it to a file. Unfortunately some of these lines have some disagreeable items. (I want to avoid foo from expanding. I want foo="...
0
votes
0answers
8 views

Adjusting the table and Gantt Chart for CPU scheduling

Is there a way to adjust the contents of the table and Gantt Chart for CPU scheduling? The code is mostly translated from C. Code for the table: printf "Program Name\t Arrival Time\t Burst Time\t ...
1
vote
1answer
28 views

Automatically copy files to external USB drive when connected to laptop

I want to copy some files/folders to a USB Flash Drive, SSD, or HDD after I connect them to my laptop. I don't want to detect the USB, do extra stuff, etc.. I just want to run a script from my ...
1
vote
1answer
46 views

Grep to check filesystem mount and test to check for file path is providing incorrect information

Even though the path exists, this script reports that it does not. What is the flaw in the logic? #!/bin/bash mount="/fileserver" if grep -qs "$mount" /proc/mount && { test -d '/fileserver/...
0
votes
1answer
50 views

Why is my bash shell script changing spaces to linefeeds?

I started out writing a simple bash shell script to find duplicate files within a given directory using SHA1 to detect matches. Everything worked until I encountered file names with spaces. The ...
2
votes
1answer
23 views

Perl Script in Bash Here Document (does not output variable)?

How come the following perl code, mkdir("foo"); print "foo: $!\n"; mkdir("foo"); print "foo: $!\n"; Will output the following (in a directory without a foo) perl ./asdf.pl foo: foo: File exists ...
0
votes
0answers
32 views

Run bash script upon change

I am running a FreeBPX on centos server and I would like to monitor phone extensions when they go offline. I have a script that is doing the job and I am running it on cron job every 30 minutes but I ...
0
votes
3answers
24 views

How to write a bash script to trigger next command if and only if the previous command's process is completed

I have a command like this which will trigger a process ./extract.sh 1553212800 1554854400 & This will give a process id for example 1234 and I want to run next command only if 1234 is ...
-1
votes
1answer
27 views

Shell script for telnet for multiple servers from text file

I am using below code for to telnet the multiple servers. file=ip.txt while read line do ip=$( echo "$line" |cut -d ' ' -f 1 ) port=$( echo "$line" |cut -d ' ' -f 2 ) if telnet $ip $port </...
0
votes
1answer
20 views

add a line to file that contains quotes and variable using bash

I want to add this line to /etc/grub.d/00_header set superusers="ubuntu" where ubuntu is the result of $USER. I've tried this: sudo bash -c 'echo "set superusers='"${USER}"'" >> /etc/grub.d/...
0
votes
0answers
14 views

Terminator layout with command that survives sigkill?

Terminator allows custom layouts with a command such as bash -lc 'npm start'; bash However, triggering SIGKILL (CONTROL-C) will kill part of the terminal and mess up your layout. SIGQUIT works but ...
0
votes
2answers
41 views

Get filenames and write them on place of previous namespace

I have hundreds of sources codes files. I want to rename namespace according to the filenames path. Of course slashes must be replace by dots. I have tried with find -exec but I failed to get the ...
0
votes
2answers
35 views

bash + regular expression + capture java version [on hold]

how to capture the jdk1.8.0_112 under /usr/jdk64 /usr/jdk64/jdk1.8.0_112/ while jdk1.8.0_112 is example and could be any other version as jdk1.7.0_112 jdk3.8.2_112 jdk1.8.0_117 jdk1.2.0_112 jdk2....
1
vote
0answers
37 views

Write stdout to a temp file using command line

Say for example we wanted to write the env from the host to Docker container, one way would be to use a temp file: env > env_file && docker run --env-file env_file image_name to avoid a ...
0
votes
0answers
18 views

Running .bsh error (ZereneStacker)

I am trying to run the program ZereneStacker on Linux (I am using a Chromebook Samsung 3). I downloaded the program's .zip from here and extracted it. According to that download page, the .zip file ...
0
votes
1answer
20 views

Output reads “ 13test.sh: line 5: [: missing `]' ” but adding brackets then directs the error to a nested if statement

The goal is to take line of usernames and then run the w command on it if it matches the who search or say that the person is not online otherwise. read -p "Enter User ID's: " str for i in [ $str ]; ...
-2
votes
1answer
61 views

Bash Script general questions

The first part of what i am mucking around with simply creates a folder entitled command_manuals that contain text file copies of all the commands available at the bash shell, the filenames which are ...
0
votes
1answer
79 views

Parsing bash output

#!/bin/bash start(){ printf 'Real IP: %s\n' "$(curl -s ifconfig.co)" set -- /etc/openvpn/ovpn_tcp/*.nordvpn.com.tcp.ovpn shift $(( RANDOM % $# )) screen -S vpn -dm openvpn "$1" # connect ...
-1
votes
1answer
71 views

UNIX Syntax (and other errors) [on hold]

A syntax error appears at line 49 on the lone else when this script is run. Can anyone point to why? Won't let me run my script. My remove script code and what my script is supposed to have are below: ...
0
votes
1answer
67 views

UNIX script is unresponsive?

This is my remove script. Not sure why my project is unresponsive, It doesn't give an error, it just doesn't do anything when I type "sh remove filename" into the command line. I have to hit CTRL C to ...
1
vote
1answer
21 views

Nested nohup mishandle output

I have a bash script A (i.e. scripta.sh) which executes another bash script B (i.e. scriptb.sh), running other commands. A: # Cool logic scriptb.sh & B: # Cool logic nohup python3 app.py >&...
1
vote
1answer
36 views

alias to turn on/off openvpn

I do have a list of *.ovpn configuration inside the directory of /etc/openvpn/ovpn_tcp/ inside that directory i do have a bash script called go include the following code which will pickup random ...
0
votes
0answers
30 views

ssh kills “while read” [duplicate]

I have a really confusing error, in the following script. reservations is just a file with 100 lines, let's say something like this: apple pear fruit ... cat reservations | while read LINE; do ...
1
vote
1answer
20 views

Non recursive .inputrc macros

I was looking to bind " to automatically insert a pair and put the cursor in the middle. Theoretically, like this: "\"": "\"\"\C-b" But this would act recursively causing this error message to pop ...
-1
votes
2answers
87 views

How come my script won't function properly?

I am trying to use my ./script.sh like so: ./compile.sh -n NAME_ALBUM -f 000 000 000 000 -l 000 000 000 000 where -n is ALBUM_NAME and corresponds to the outputted filename being saved where -f ...
0
votes
1answer
48 views

How to modify this `printf` code to accept input in first to last order, or flip output?

Code below can, for example ... [anony@mous-pc ~]$ (printf 'g?%s?m0\n' 008 006 004 002 ; printf 'wq\n') | ed -s file.txt ... take all of numbers within ... [anony@mous-pc ~]$ cat file.txt 005 003 ...
3
votes
2answers
70 views

How to include custom command options in a bash script with $1 and $2?

I have a script myscript.sh #!/bin/sh echo $1 $2 which is used something like ... ./myscript.sh foo bar which gives me an output of ... foo bar but how can i make this script include custom ...
2
votes
1answer
32 views

Parsing arguments with nested case statements

I am trying to build a program with 2 modes, each mode takes a different set of arguments. I have tried to implement nested case statements as described by @geekosaur in here, with case "$1" going ...
5
votes
3answers
2k views

Does FOO=bar; export the variable into my environment?

If I run FOO=bar docker run -it -e FOO=$FOO debian env That environment variable is not set in the command output for the env command. PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/...
0
votes
0answers
26 views

Do not allow detach for one bash

I would like to know if it's possible to forbid all detached-like things for a given shell. More precisely, I'd like to make sure that if a command runs in a specific shell, when the command stops, ...
0
votes
1answer
71 views

How to execute .sh with certain file which has .xyz extension [on hold]

I have abc.sh file and input source (input.xyz). I always execute the abc.sh file with input sourece (e.g. I type sh abc.sh input.xyz) However, as the number of directory increases I cannot bother to ...
9
votes
3answers
299 views

How to remove new line added by readarray when using a delimiter?

VAR=a,b,c,d # VAR=$(echo $VAR|tr -d '\n') echo "[$VAR]" readarray -td, ARR<<< "$VAR" declare -p ARR Result: [a,b,c,d] declare -a ARR=([0]="a" [1]="b" [2]="c" [3]=$'d\n') How can I tell ...
0
votes
2answers
46 views

Converting bash to ksh

My current shell is bash and I want to convert to ksh. I tried to convert through chsh or ypchsh but dont have permission to convert. So I tried to convert using .bash_profile as below $vi ....
0
votes
1answer
33 views

Batch download a series of files and add prefix to them

So I have a list of downloadable links with a specific order, but the filenames are jumbled up example.com/ddk.zip example.com/453.zip example.com/hth.zip So I want to automatically prefix them as I ...
0
votes
1answer
50 views

Control a bash instance by a script (in a robust way)

I'd like to control some bash programs (local, or ssh) with some (eventually interactive) scripts (say python) in a robust way. I'd like to send commands, get the stdout/stderr of that command at the ...
-1
votes
3answers
56 views

Variable for SCP command in script

I'm trying to write a script that will check what is the last modified/created file on the server, then copy it to my homedirectory on this server and then copy this file from node to my local machine....
1
vote
1answer
42 views

Bash script to connect to *.ovpn randomly

I'm trying to edit the following bash script to connect to vpn randomly from the list of .ovpn files inside the directory. I've downloaded the following ovpn files from nordvpn List of NordVPN OVPN ...
0
votes
1answer
34 views

Redirecting to both screen and file

I'd like to redirect all of the output of the commands I ran to a file, in addition to having them printed on the screen. I want this to happen automatically, I don't want to pipe into tee everytime ...
6
votes
3answers
399 views

Shell builtin `printf` line limit?

The /usr/bin/printf util argument list length is limited to the shell's maximum command line length, (i.e. getconf ARG_MAX, on my system that'd be 2097152); example: # try using a list that's way too ...
2
votes
0answers
31 views

Why does the touch command works in one directory and not in the other?

On the same mount, the touch command sometimes doesn't work Using different directories on the same mount, the touch command gives different results **bob@syno ~ % ll -d /volume1/media ; ll -d /...
2
votes
5answers
120 views

Filter a file list against an integer array?

I have a folder with lots of images named "clip01234-randomlongstring.png", where 01234 is a random five digit number. I also have an array "clipnumbers" with a list of integers. Now I want to ...