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. For shell scripts with errors/syntax errors, please check them with the shellcheck program (or in the web shellcheck server at https://shellcheck.net) before posting here.

Filter by
Sorted by
Tagged with
0
votes
1answer
21 views

Custom data formatting and pattern matching

I am trying to format custom data using pattern match. I am not getting expected format. Though I am not shell script savvy but I was able to build a script based on references from multiple sources ...
0
votes
1answer
27 views

**Performantly** skip the first N bytes of a stream

I know to use tail -c +N, but it is extremely slow, and pins a CPU core: leijurvs-MacBook-Pro:Downloads leijurv$ time cat /dev/zero | head -c 100000000 | shasum -a 256 ...
0
votes
0answers
36 views

How to use column with tput colors?

Using tput colors seems to disturb the output of column. Why does this happen and more importantly is there a way around it? $ { echo "$(tput bold)foo$(tput sgr0)" "$(tput bold)bar$(...
0
votes
1answer
55 views

bash Noob: What's wrong with this line?

I'm trying to make a bash script written for BSD work on Linux, in case that's relevant. Now I'm stumbling over this line: json="$(sudo -u "${vpnUser}" -- curl --interface "${...
0
votes
1answer
27 views

Help with understanding Globbing in the Context

[ ! -d ~/.ssh ] && mkdir ~/.ssh; I cannot understand the use of [] here and what does this mean. Although I understand the later part I cannot relate [ ! -d ~/.ssh ] with mkdir ~/.ssh ...
0
votes
0answers
14 views

Unexpected behavior during index assignment in a Bash array [duplicate]

I'm having trouble assigning values to a specific bash index, but apparently only when the index variable is set using a while read loop. Taking this code as a test example: #!/bin/bash read -d '' ...
-2
votes
2answers
51 views

How can I delete .bash_history file forever? [closed]

I want to delete .bash_history file forever and I don't want to see this file again. Can I delete this file forever? Is it possible to do? If it is, how?
1
vote
0answers
18 views

Run the same command

I constantly need to close and re-open programs. To do this I press Control+C > Up Arrow > Enter. However, I have more than one program and need to run different commands for these programs. If ...
0
votes
0answers
10 views

Sourcing Env variables in Perl Script

i have a Perl script to run ,before running the Perl script i will run "source some directory"(contains Env variable) and after that i will run the perl script it will works. Question how ...
0
votes
1answer
20 views

How to check memory utilization in solaris 11 machine?

May I know how to calculate total memory utilization and percent of a solaris 11 machine? Am I wrong in below calculation? or any other way? memfree=$(vmstat 1 2 | awk '{print $5}' | tail -1) memtotal=...
0
votes
3answers
42 views

how to redirect multiline bash command into a variable

I want to redirect this command to a variable: { printf 'scan on\n\n' sleep 10 printf 'quit \n\n' } | bluetoothctl I tried to do this: variable=$(printf 'scan on\n\n' sleep 10 printf '...
0
votes
2answers
57 views

How to use a for loop in order to save the output from a script into single files

I got help subtracting a random 200 sequence from a fasta file like this: JQ086372.1 Enterobacteria phage HK446, complete genome ATGGCAGATAAACGAATCCGTTCCGACAGTTCGGCGGCAGCGGTTCAGGCCATGAAAAATGCAGCTGTGG ...
1
vote
1answer
20 views

Signal lost for Bash background process

When I spawn a background job in Bash 5.1 and immediately send it a signal, this signals seems to get lost. Short demo: $ cat simple.cc #include <signal.h> #include <unistd.h> #include &...
0
votes
1answer
34 views

If Bash arrays can't contain a null string, how does this array do it?

I've recently discovered that you can't pass a null string to a Bash array. This is tricky, as I'm trying to insert an empty string value into an array. I've noticed that the Bash completion variable ...
2
votes
2answers
107 views

Output concatenation of file contents and custom text into a new file

Sorry for a noob question but, well, I am a noob, so... Given two files, say file1 with content, say, text1 and file2 with content text2, I want to create a new file file3 with content ...
-1
votes
1answer
38 views

How do I check if the server.log is updated everyday?

I want to check if server.log is updated daily and also print the last few lines of the log . The format in which the log file name is server.log.2020-12-02
0
votes
1answer
63 views

Close terminal window once application is opened

Is it possible to close the parent terminal window once an application has been loaded? I have a program I need to run using root privileges to work properly and currently I have made a script file ...
1
vote
1answer
32 views

Compare columns conditionally between two files in awk

I've looked up examples with awk but I'm struggling to use arrays properly when comparing multiple conditionals. I have two files and I want to return information when two conditions are met: Column ...
0
votes
1answer
70 views

Linux. Why does my Linux command work on the terminal but it doesn't work in a script

#!/bin/bash ps -fu Jor970 --rows $(($(tput lines) --cols $(tput cols) --headers | less
1
vote
1answer
31 views

Understanding Bash I/O redirection

I have a pretty good idea how file descriptors work in Bash to accomplish I/O redirection in a practical level, but there is a case I found online (https://linuxcommand.org/lc3_adv_dialog.php, under &...
0
votes
0answers
4 views

What is the difference between USB port bind/unbind and autosuspend?

I have a small server, with Ubuntu OS, running 24/7, and with a script that is triggered only once a day to retrieve data from the net, and copy it to an external USB hard drive. This data copy is ...
1
vote
0answers
14 views

How can a device be mounted on several mount points, while directory listings for the mount points list different files?

Consider the device called /dev/mapper/systemvg-varlv. It's mounted on /var, /var/lib/docker/containers, and /var/lib/docker/overlay2 and its filesystem is XFS. If the same filesystem is mounted on ...
0
votes
2answers
24 views

Mounting an external SSD with user privileges using fstab

I have entered the following command: sudo mount UUID=17F30CD71ED138A1 -o gid=1000,uid=1000 ~/sandisk_external_drive It worked great, but now I'd like to mount it on boot, therefore I have added an ...
0
votes
0answers
8 views

Man Synopsis Doesn't Have Libraries Which Needs [duplicate]

When I write "man fork" in Linux Mint, it gives When I write "man fork" in Ubuntu, it gives As you see, Linux Mint terminal has libraries which need for "fork" but ...
1
vote
1answer
38 views

GNU parallel bash

I am learning GNU parallel and I wonder it this makes sense: bash: IFS=" " while read field || [ -n "$field" ]; do targets_array+=("$field") done </...
0
votes
1answer
51 views

How to interactively run all commands in a file in zsh?

I came across this question. It asks for a way to interactively run all commands in a file. One answer proposed using a bash script like this: #!/usr/bin/bash ...
1
vote
4answers
122 views

How to randomly extract a substring of 200 characters from a fasta file

Is there any Linux command one can use to extract a sequence from a file? For instance, a file contains one million lines, and we want to randomly sample only a sequence of 200 characters from that ...
2
votes
3answers
41 views

arguments limit php exec() to bash script

Testing how long will it take to pass 50000 arguments from php to a bash script, turns that I cannot pass even 1000 arguments from php to a bash script at once, unless I can? PHP: $array = ...
0
votes
1answer
29 views

Rename files in any deep subfolder like the parent folder and move after to a central folder

I have a problem where I need to rename just certain files after the parent folder and afterwards move these to a central folder. Is there a way to do this? I would like to run this on a Synology NAS. ...
0
votes
1answer
30 views

Trying to move words from dictionary using grep command to append .txt file

Doing a project going for extra credit by making script to do work for me instead of me typing in commands over and over. I need to move several words from a file. Not just the words, but words ...
0
votes
1answer
22 views

1748048961/source.sh: line 133: unexpected EOF while looking for matching `"' 1748048961/source.sh: line 138: syntax error: unexpected end of file

#!/bin/bash # #Lisa You # #12/1/2020 # #Purpose of the script: The user can use the script to copy, read, rename, and delete files. # #Use of while loop to continue task until the user answers NO to ...
0
votes
2answers
23 views

Run a command along with arguments in bash

I have a bash script which looks like #!bin/bash # array to store my commands COMMANDS=(route ls -l ) # here I want to iterate through the array, run all the commands and take # screenshot of each ...
1
vote
1answer
8 views

Getting name of logrotate file?

Let me start by saying I'm very new to linux and bash scripting, only been at this for 2 weeks so assume I know nothing! For development reasons, I need to copy a log file to another location and name,...
1
vote
1answer
31 views

using CentOS7 yum command not working in root

I get this when I use yum: $ yum -y update -bash: /usr/bin/yum: /usr/bin/python: bad interpreter: No such file or directory So I followed an online answer from here: $ sudo rm -rf /usr/bin/python $ ...
4
votes
3answers
312 views

Why must I put the command read into a subshell while using pipeline [duplicate]

The command df . can show us which device we are on. For example, me@ubuntu1804:~$ df . Filesystem 1K-blocks Used Available Use% Mounted on /dev/sdb1 61664044 8510340 49991644 15% /home ...
-1
votes
1answer
42 views

why does `echo` works but `cat` does not when pipeing to `openssl`

I was looking at Most straightforward way of getting a raw, unparsed HTTPS response to make a GET request to a url over HTTPS, and receive the raw, unparsed response. the following works: echo 'GET / ...
0
votes
1answer
42 views

Can someone look at my code and see what I have done wrong?

The code I have is supposed to ask for the user to enter a name of a directory they wish to create, then it is supposed to ask to edit files within the directory, however when after I create the ...
1
vote
1answer
73 views

How to interactively run all commands in a file

I have a text file commands.txt that has over a hundred lines, each of which is a shell command: echo foo ... echo bar I want to run each line in the file, but I would like to check each line just ...
-1
votes
1answer
52 views

Using CSV file with Bash

Looking to use a csv file that uses headers as variables that change at each line but I want to do something simple like run a while read -r or For loop off each line. During the loop I want each ...
0
votes
2answers
52 views

How do I store network information in variables in BASH?

I am writing a bash script and need to store some primitive network information in separate variables. For example, mac address and IP address in separate variables, for example IPADDRESS=$(...
0
votes
0answers
49 views

Set credentials as environment variables

I want to now, how to use credentials as secure as possible in automation tasks. In the following post on medium.com the author uses environment variables to store credentials, which he want to use in ...
0
votes
3answers
41 views

Pass args to bash script from git using curl

I'm looking for ways to pass arguments to a script fetched from git using curl, and my script requires an argument. Is there any way that arguments can be passed to script as following: bash <(curl ...
0
votes
1answer
25 views

tmux: How to always resize all windows to maximum available size?

I am running tmux 3.0a, and when I connect with a smaller resolution terminal, also the bigger terminal gets resized to the smaller. This is well known (although I don't understand why they made this ...
1
vote
2answers
49 views

Append to file specific entries of syslog

As usual, I can inspect the contents of syslog entries in this way: cat /var/log/syslog | grep myentry I need to append all myentry rows to a specific file. Of course just redirecting the output of ...
0
votes
1answer
27 views

Checking string validity

In one script, I am getting the exifdata out of 20000+ photos and videos in various formats. As I'm extracting the creation date, it works in most cases, however exif data is as good as the device ...
0
votes
0answers
12 views

How to mock Pacman package?

I've just finished a script to print out the contents of a file in a Pacman package (based on pkg-extract_original), but I'm having trouble testing the final functionality. Basically I have a test: ...
2
votes
4answers
220 views

How to tail the last 4 modified files?

I feel like I am missing something very simple and I was wondering if it possible to sow the last few lines of the last 4 modified files. I tried something like this tail | ls -lt | head -5 but I ...
-2
votes
1answer
41 views

Communicate the data or path from .sh file to .csh

I am able to execute the .csh file from .sh file. I want to pass the path from a.sh file to b.csh file when it starts to execute the .csh file. eg:- #a.sh if(result=0) then x=path/to/.csh #I want to ...
-1
votes
0answers
21 views

Why variable substitution is also called variable reference?

Why is variable substitution also called variable reference? In C/C++ the reference operator (&MyVariableName) returns the pointer address of a variable. In bash programming instead, we talk about ...
1
vote
2answers
30 views

How to autocomplete a shell command starting with (an alias involving) sudo

Assume one has the following alias in your .bashrc: alias docker='sudo docker' then try to autocomplete docker run -v /tmp/test:/foo … in a bash terminal, starting from docker run -v /tmp| → due to ...

1
2 3 4 5
419