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.

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

How to check NGINX configuration using Bash?

I need to programmatically check the NGINX configuration for correctness using bash. The result of the nginx -t command is assigned to a variable, and by the condition I compare the substring - syntax ...
1
vote
0answers
13 views

What's the preferred way to implement a toggling script?

By 'toggling script' i mean a script that when run turns something on and the next time it's run turns it off again. The example that brought me to this question is audio device mute toggling. ...
0
votes
0answers
11 views

How I can get $(logname) inside systemd exec command?

I'm writting a systemd service (/etc/systemd/system/name.service). This service execute a script placed in ~/folder/script.sh. I can't use ~/ inside the ExecStart command so I use /home/$(logname)/...
0
votes
0answers
10 views

imagemagic: convert +append images : pass the list of files in numeric order rather than alphabetical order [duplicate]

I am trying to join few images into one single image These are the list of files i have to join them horizontally slice_0_0.png slice_0_2.png slice_0_4.png slice_0_6.png slice_0_8.png slice_0_10.png ...
0
votes
2answers
21 views

Environment variables don't expand correctly when related to a function

Here is a part of my .bashrc file: echo_pwd () { echo `pwd` } export echo_pwd="`echo_pwd`/" I created a new function echo_pwd that prints the path of the current directory and a new environment ...
0
votes
1answer
21 views

How to avoid rc.local been executed?

I created a rc.local in /etc/ on Ubuntu 18.04 The content is sleep 180 reboot I thought I can stop this during the 180 seconds, but the fact is it just hang there waiting 180 seconds then reboot. ...
0
votes
1answer
24 views

Pause execution of a list of commands

I have a file that has a list of bash commands like the following: echo 'foobar' echo 'helloworld' echo 'ok' And I can execute these commands by simply piping them to /bin/bash like so: cat ...
0
votes
0answers
6 views

Unable to set a value with “gsettings set”

when i open a terminal in NX, it is not loading .bash_profile. But when i change the terminal settings, I enabled "run command as a login shell" via Terminal --> edit --> preferences-->under profile,...
0
votes
1answer
11 views

Creating a bash script to change permissions with Deluge execute plugin

I'm trying to make a script in bash (first time) for the Deluge plugin execute so after a download is complete it will change the permissions of the downloaded torrent. its: #!bin/bash torrentpath=$...
-1
votes
2answers
71 views

Why does echo * behaves as ls and printf * not?

Consider these shell commands $ls my_app newlist note and $echo * my_app newlist note and $printf * my_app The first command ls will List information about the files (the current directory ...
2
votes
2answers
58 views

Environment variables when running unshare

Is there any namespace (process, user, etc) that isolates environment variables? In case there is, what happens when you unshare? Do they get cloned? What happens if a process changes an existing ...
0
votes
2answers
27 views

Why does the terminal show different output when I'm connected as the same user running the same command?

I SSH'd to a Linux machine using the same user and ran the same command as shown below, but the output is different. I'm relatively new to Linux, so I would appreciate an explanation for what I'm ...
0
votes
0answers
27 views

Bash variable not saving new data given? [duplicate]

I wrote a Bash function: disk_usage() { CAPACITY=0 USED=0 FREE=0 df | grep /$ | while read LINE ; do CAPACITY=$(echo "${CAPACITY}+$(echo ${LINE} | awk '{print $2}')" | bc ) ...
0
votes
2answers
34 views

bash script counting lines

I am trying to write a bash script on a Linux machine to count lines and stop at Firmware state: Rebuild, then get that line number (e.g. 15 -1 = 14, since line number 0 is the first line) and save it ...
0
votes
1answer
34 views

How do I delete a folder but only keep selected files?

My folder structure is as follows: Photos | |---> 2015-08-23 | |---> IMG_0019.JPG // keep IMG_0019.JPG.json // toss IMG_0020.JPG // ...
2
votes
1answer
57 views

Why can't I see the manual for > but can see it for [?

I just did man [ and it opened the manual. Then I tried doing man > but I get this error: -bash: syntax error near unexpected token `newline' How is > different from [?
-1
votes
0answers
44 views

Discover what file stdout is being written to

Answer is probably out there somewhere - say we have a shell redirection: node foo.js > /tmp/foo.log is there a way from the node.js process to determine which file stdout is attached to? I ...
0
votes
0answers
42 views

How to list all internal commands of a shell

Is there any way to list all the internal commands of a shell. I am using bash shell. if I type echo then bash has internal echo command so internal echo command will be executed( Internal command ...
0
votes
0answers
45 views

How to output only certain lines from a file having the line numbers in another file? [duplicate]

I have a file with desired line numbers: 4988 5008 5028 5050 5072 5094 5116 5138 5160 5182 5204 5224 . etc . These are line numbers indexes into a log file that I have: URL : https://dc4-...
0
votes
1answer
44 views

bash script - how use a $variable in grep

I am writing a simple bash script where user input the domain name (example.com) and it greps the email address from whois command output. I want only grep the email with the same input domain (xxx@...
0
votes
1answer
30 views

word count redirect

I can't seem to answer this question: Use the command wc to count the number of words in the file /course/linuxgym/gutenberg/0ws0310.txt. Store the exact output of the wc command when used with the ...
0
votes
3answers
67 views

In bash: trailing space capture in variable substitution

I see this in BASH 4.3.48 (SLES12 SP4) and BASH 4.4.23 (OpenSUSE Leap 15.1) when trying to remove multiple trailing spaces from a variable's value: ~> xxx="-O -Wall " ~> echo "X${xxx%% }X" #...
-1
votes
0answers
42 views

How to remove duplicates in excel both rows and columns using shell or awk script across multiple files

How to remove duplicates in excel both rows and columns using shell or awk script across multiple files. If the second file contains a row which already exists in previous file, then it should be ...
0
votes
0answers
29 views

Feed gdb stdin with multiple inputs from a file

This has been driving me crazy and it must be so simple! I've looked at many solutions but none seems to work with my application. I'm debugging a program in gdb. The program takes two inputs like ...
-4
votes
1answer
44 views

Writing a bash shell for loop question [closed]

trying to write a Bash shell for loop that will iterate through each line of the confidential.hex file and add each line of the hex string to the name of target domain name server, ns.example.com and ...
-1
votes
4answers
36 views

Mv files with number formatted in 2 digits

I would like to mass rename files from: "02 Disc 01 My Song.mp3" to "Disc 01 My Song 02.mp3" How can I do this in bash? Please note that all numbers are formatted in two digits (1-9 is ...
0
votes
2answers
34 views

search multiple files based on file contain string

let say i have one text file contains emails abd3@dom abd2@dom sdklf2@lksd sd@gm i need small bash script for grep , find , to find contain the email in files and and print out the files they match ...
-4
votes
3answers
59 views

Parsing ranges into discrete values, in Bash

User will provide a list containing ranges. I need to convert it to a list of discrete values. For example Input host[1-5],host7,host[13-15] Output host1,host2,host3,host4,host5,host7,host13,...
0
votes
1answer
35 views

Bash script array with and without values

I have a couple variables a, b and c. On a for loop I wanted to display all their values. for i in ${!a[@]}; do echo "${a[$i]} ${b[$i]} ${c[$i]}" done Now values are shifted to the top since ...
0
votes
0answers
13 views

Is there a way to pipe to a visual editor and then continue the pipeline? [duplicate]

I know that some command-line programs can open visual editors like Sublime in a "wait mode" which opens the editor, lets you edit, and on-close it resumes the program with the file contents (like git ...
1
vote
0answers
29 views

How to run function in remote server using ssh and expect [closed]

I need to run a function on a remote server over SSH. I'm using expect to automate login to remote server. On remote machine, I can run command, local scripts, but function is not working. I get "bash:...
0
votes
2answers
27 views

Test size of newest file

I want to check if the size of the newest file is greater than 2 MB: test $(ls -st | head -n2 | tail -n1 | awk '{print $1}') -gt 2097152 && echo "true" Is there a more efficient or elegant ...
0
votes
1answer
24 views

How to fix my error when trying to update on vmware kali?

I have Vmware workstation player 15 installed Kali Linux 2020.1. When I try to update on vmware kali I'm getting this error: Could not open lock file /var/lib/apt/lists/lock - open (13: Permission ...
0
votes
1answer
37 views

crontab cannot find environment variable even after sourcing .bashrc

crontab -e 00 00 * * * /home/username/run.sh >> /home/username/log 2>&1 Inside run.sh: source /home/username/.bashrc java When crontab job is triggered, I got this error in the log: /...
0
votes
5answers
37 views

How to extract a certain string and delete rest of values from an input string?

INPUT="TEST: www.google.com TEST2: 123444 TEST3 Id: ABCD1234 TEST.txt" My expected output is ABCD1234 I tried OUTPUT=`echo $INPUT | sed 's/^.*TEST3 Id://' | sed 's/\[space].*//'` Got this as ...
8
votes
4answers
999 views

Where can I find a definitive answer for what `*/` means in Bash or Zsh?

I was trying to look into some reference from O'Reilly about Unix and Bash about the meaning of */ but couldn't find any. We can echo */ and see all the directories. It seems like it means all "...
-1
votes
1answer
30 views

What does the at sign `@` and `+` sign mean when doing `ls -l` [duplicate]

This is on macOS Mojave. I tried to get the size of directories by using du -csh */ in my home directory. But the directory Library was giving Operation not permitted. So I used sudo to do it, ...
0
votes
0answers
36 views

FIFO is not blocking on write on MacOS [closed]

Update: my testing method was not correct, sorry. The write blocks as expected on Mac. The Linux man says that writing to a FIFO should block when not (yet) read from: Opening a FIFO for reading ...
0
votes
1answer
19 views

Bash script for monitor the API json response

I want to monitor the below health check URL. I need generate a alert if mongodb goes to disconnected state. I wrote a bash script. Seems its still not working. Any can help on this ? Thanks When do ...
0
votes
2answers
27 views

How to find out all the sizes of GB of directories under the home directory?

On the Bash on a Mac, It is possible to do something like cd # go to home directory ls -d */ to get the name of the folders in the home directory. And we can use du -sh Documents to get ...
0
votes
0answers
43 views

Variable losing value [duplicate]

Anyone have suggestions? Thanks in advance. #!/usr/bin/env bash VAR=$( ssh -q -T -o ConnectTimeout=10 server01 " df -Ph" ; EXITSTATUS="$?" | sed -r '/^\s*$/d' | grep -v "test" | wc -l ) echo $...
0
votes
2answers
22 views

Passing string command line argument to bash script for a particular linux command

I have found the following command online to search texts in pdf's find . -name '*.pdf' -exec sh -c 'pdftotext "{}" - | grep --with-filename --label="{}" --color "your pattern"' \; I want to ...
0
votes
1answer
38 views

How to track a login console crash?

I have a Jessie install that wont allow me to logon. It boots up, presents the prompt, accepts the username and password, but just blinks and comes back to the login prompt. It appears that Bash is ...
0
votes
1answer
33 views

Split a long string made of number-dot-number-space pattern separating the digit on left and on the right of the dot in bash

I am reading a csv file with dm=`awk -F "\"*,\"*" '{print $1}' file.csv` I am keeping the first column, which looks something like: 25.3 26.3 27.3 for several rows. I want a variable made up of ...
0
votes
0answers
25 views

How to break out of read loop in pipeline consumer

I have this mini script: #!/usr/bin/env bash do_tests(){ # todo } go run . | ( while read line; do if [[ "$line" == "listening" ]]; then do_tests # run this once! break;...
0
votes
1answer
26 views

Use !! from within a bash function

I am trying to write a bash function in my .bashrc that reruns the previous command in the history and does something useful with the captured output. my_function() { output=$(!!) # Do something ...
5
votes
3answers
263 views

Find files and check if they were executed successfully

I would like to count successfully executed files, but I can't get it to go. This is what I have: successfulScripts=0 allScripts=0 commandline=$(find . -name "*.sh" -exec '{}' \;) if [ $...
0
votes
1answer
54 views

POSIX floating comparison

working with a legacy system, here I'm connecting with sqlplus to store the returned value in a variable and its worked fine with me but the problem with compearing with floating values a numeric/...
1
vote
1answer
32 views

How can I recursively find directories and parse them into python script call within bash script?

I am attempting to look into multiple subdirectories within a single directory, and plot the files in each subdirectory using a python script that I am calling within this bash script using gnu-...
0
votes
2answers
30 views

How to perform artihmetic operation in awk if condition

I am working on checking if a particular file existing in the directory is older than 30 mins or not. curr_epch=`date +%s` curr_epch_buff=`expr $curr_epch - 1800` ls -l --time-style=+"%s" | grep ....

1
2 3 4 5
381