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

sed remove all occurrences of a string in a file

Hey I have a huge text file which contains a set of strings I wish to remove, can anyone help as I'm having difficiulty. String to remove @This("is") probably being the contents inside the quotes ...
0
votes
1answer
15 views

How to embed a bash function into a sed expression?

In sed how can I create a replacement string using a bash function, especially a function of one or more of the found parts, normally identified as \1, \2, ...? In other words, I want to do something ...
6
votes
2answers
1k views

Bash function to wrap program and sometimes append argument

I'm interested in a general solution, but my specific example problem is writing a .bashrc function that wraps grep and appends a file path to the command if missing. Basically, any time grep would ...
-1
votes
1answer
21 views

How to define the name of a bash function to be a regex

I've searched around and can't find an answer. I want to define a function like this function \d{2} () { echo $1_or_smth } Then if I say in my terminal 12 I want it to echo 12 back.
0
votes
1answer
17 views

Run bash script on network changes

How can I set Ubuntu to run a bash when network changes. Like changing local IP, connecting VPNs, disconnect one interface and connect to another.
0
votes
2answers
26 views

Variables being called with if statement gives -bash: 'Command not found'

I'm modifying my .bash_profile file so that when I run ipy it clears the log file every seven or more days. The problem is when ever I reference a variable within my if statement I get back -bash: ...
0
votes
0answers
9 views

Underlying failure after a SIGPIPE

I am getting an error code 141 when running a bash script on a CI server that I cannot reproduce locally. After some searching, it sounds that error 141 indicates a PIPEFAIL, and I have a set -o ...
0
votes
1answer
12 views

Why does `complete` sort options even with `nosort`?

I can't get this answer to work in Bash 4.4.20 (default shell in Ubuntu 18.04): $ complete -o nosort -W '--color=auto --color=always --color=never' mycommand $ mycommand --<Tab> --color=always ...
0
votes
2answers
75 views

How can I check if a program is installed in the most compatible way?

A BASH script I wrote has two requirements. At the moment I check if they are installed this way and I thought it was a good solution until I had some complaints from users: command -v fping >/...
1
vote
2answers
1k views

Script to see if user has logged off

I have created this program to see if a user is logged on and it checks every minute. if [ "$#" -ne 1 ] then echo "Usage: mon user" exit 1 fi user="$1" until who | grep "^$user " > /dev/...
1
vote
1answer
18 views

how to change value of parameter recursive under folder

under /etc/sysconfig/network-scripts , we have network configuration files as ifcfg-conf1 ifcfg-conf2 . . . is it possible to change all parameters - PEERDNS to no , if value is yes expected ...
124
votes
7answers
68k views

Temporarily suspend bash_history on a given shell?

Is there a way to temporarily suspend history tracking in bash, so as to enter a sort of "incognito" mode? I'm entering stuff into my terminal that I don't want recorded, sensitive financial info.
3
votes
1answer
249 views

What is this script doing?

#!/bin/bash echo 123456789 > out.txt exec 3<> out.txt read -n 4 <&3 echo -n 5 >&3 exec 3>&- Was asked the content of out.txt at the end of script, in an interview ...
2
votes
2answers
1k views

How to write output to a file of the same name as the input?

I am wondering how to to process files from some folder dir1 if they are piped through various tasks and in the end I'd like the output to be written in the same folder structure and file names, i.e. ...
0
votes
0answers
20 views

Building Kali Linux image from inside Live USB with custom build directory

Introduction: Kali Linux has special scripts for self-building the image and everybody can adjust all the parameters (DE, packages, pre- post-install scripts) and make his own ISO. The problem: when ...
1
vote
1answer
23 views

Install “info” in Debian

When I run the info command I get bash: info: command not found How can I solve this?
2
votes
1answer
71 views

Difference between connecting shell commands

My tab completion (BASH in debian) shows me different numbers for combining two commands subsequently. It's somehow common sense that I can execute more commands the more privileges I have, e. g. with ...
-1
votes
1answer
33 views

echo alias prints space between env variable and first argument

have a weird problem..... Im configuring my arch setup and one of my aliases isnt working..... alias es='echo $SCRIPTDEST/$1' For some reason it prints a space between $SCRIPTDEST/ and $1, ruining ...
2
votes
2answers
53 views

localize shopt options

I would like to temporarily change the value of a certain shopt option in a function. For options which can be set with the builtin set this is possible with local - inside the function body. The ...
0
votes
1answer
21 views

./txtdb: line 9: [: =: unary operator expected

echo "Choose from the following options" echo "1- Display full Database" echo "2 - exit program" read usrChoice if [ $usrChoice -eq 1 ] ; then cat energydrink.txt elif [ $userChoice -eq 2 ] ...
0
votes
1answer
26 views

How do I specify a date range in a wget script for multiple files to only download what I need?

I am trying to download a lot of data for some research from the CMIP6 website that provides wget scripts for each model. The scripts are for every 6 hours or month from 1850 to 2014. The date ...
1
vote
1answer
2k views

Running Python script over multiple directories and multiple files

Here is my command line for python: python script.py -a .faa -n .fna I have a directory containing multiple directories. Out of these multiple directories, there could be 1 or more folders. In ...
-1
votes
0answers
62 views

Linux Internal working of `cat`

TL;DR I was writing a very simple bash script, which goes into each folder in my pwd and find for files with names pid. If yes, echo that file out. pids=$(cat */*/bin/*pid) echo $pids >> ...
1
vote
0answers
18 views

unknown filesystem grub rescue + chroot doesn't find `/bin/bash`

I was installing hyperledger fabric, on Ubuntu 18.04.3 Desktop, through sudo -E, with bootstrap.sh and of another similar one. But after installation, which seemed gone fine, I'm not able to use ...
0
votes
2answers
33 views

Change prompt with echo to show current directory

Problem: I was hoping this would be something simple to do. I currently have my script changing my directory among other things and I was hoping that I could make the script change the line using ...
0
votes
1answer
24 views

Making the first word I type on terminal of different color from the others

New here. I was trying to make the first word I type on the terminal of a different color from the others. I have looked into the .bashrc file and /etc/inputrc files. I know that I can make use of the ...
0
votes
2answers
53 views

How do I save the output of a script to a file?

I have the following script: LOOKUPS=/tmp/$0.LOOKUPS.$$ OK=/tmp/$0.OK.$$ KO=/tmp/$0.KO.$$ NOVENUE=/tmp/$0.NOVENUE.$$ trap "rm -f $LOOKUPS $OK $KO $NOVENUE" 0 1 2 3 4 5 13 15 tu=`$APP_SERVICE | cut -...
1
vote
3answers
4k views

Shell script to ls and execute command on ls result

I have a list of folders inside a folder in ubuntu. ie. Under /mnt/source/customcode/files/brands/ root@a919794ec280:/mnt/source/customcode/files/brands# ls -la total 236 drwxrwxrwx 19 1002 root ...
1
vote
2answers
42 views

value of loop variable is null after SSH connection

I am trying to write a script that will do ssh and run a few commands on the remote host with help of loop. One of the problems I've run into is that, when I run the for loop, it outputs is null. ...
0
votes
0answers
7 views

Processing CUPS spooler data file

We are doing image processing of CUPS data file. So we are capturing data files of particular print queue. But we are not able to capture number of copies information in print job. We tried to ...
0
votes
1answer
853 views

How to write Docker logs to a file in real time (à la `tail -f`)

I docker that output logs stdout stderr, which can be viewed using: docker logs -f $LOGS_CONTAINER_ID I also added 'sed', which puts the container id on each line: docker logs -f $LOGS_CONTAINER_ID ...
1
vote
2answers
32 views

How to run Bash Script in background [duplicate]

I am remotely connected to a system using ssh and want to run nmap on a system from there. But every 5 minutes, my SSH connection breaks and so the process running on my shell stops. How can I run ...
0
votes
0answers
19 views

Check whether file content equals the output of a given command

Autostart graphical application only for first login of the day of a user I'd like to start lxtask automatically after the first login of the day with openbox. I included the first line of the ...
0
votes
1answer
22 views

How do I prevent sideways scrolling (and get wrapping instead) of long bash command-lines in CentOS8?

Normally, bash command-lines wrap - which I am used to and works great: [cnd@MacBook-Pro ~]$ echo abcdefgABCDEFGhijklmnopHIJKLMNOPq rsQRStuvTuvWXYZ (I made my window narrow to demonstrate) However -...
0
votes
0answers
14 views

Meaning of uint32:0 in dbus-send and bash syntax

dbus-send --system --print-reply \ --dest=org.freedesktop.DBus \ /org/freedesktop/DBus \ org.freedesktop.DBus.StartServiceByName \ string:org....
48
votes
10answers
140k views

Script to change current directory (cd, pwd)

I want to run a script to simply change the current working directory: #!/bin/bash cd web/www/project But, after I run it, the current pwd remains unchanged! How can I do that?
0
votes
0answers
36 views

Configuring cron from shell script

I have a shell script with the following lines (the full script at the end of post): CRON_BCK_CMD=/home/user/bck.sh CRON_CONF=" */30 * * * * $CRON_BCK_CMD" but when I simply run these in ...
2
votes
0answers
39 views

Why did bash (or PuTTY) interpret the two characters 'cd' as the single character '㏅'?

I ssh'd into a CentOS VM today through PuTTY -- right after I logged in and got a bash shell, I tried to cd to another directory, but the displaying of what I typed lagged a bit, and then instead of '...
7
votes
2answers
62k views

Combining multiple commands into a single line

I had a directory named myname which was archived in myname.tar. Now I want to take myname.tar, unarchive it, and delete all the files in the myname directory (after unarchiving). Here are my ...
49
votes
5answers
10k views

Intended use of ctrl+T in bash?

I noticed bash has a short cut for ctrl+T which swaps the last two characters before the cursor. I'm wondering why the engineers decided to include this. Was it inherited from a previous convention?...
1
vote
1answer
27 views

.bashrc or .profile for busybox on windows

I have enough experience with scripting on *nix servers, but busybox on Windows I enjoy first. I installed busybox using scoop. When I run: ash echo $HOME I got -> C:/Users/RO # OK, this is dir ...
1
vote
1answer
62 views

How do I get rid of boxed '?' symbols that appear after every character in tmux?

When I run tmux, every character has a boxed '?' next to it. The boxed '?' symbols also appear after every character I type when I am within vim when I am in tmux. I have been doing research online ...
-1
votes
0answers
26 views

smart_script alias [closed]

When I call a certain alias from a bash script on my Linux 16.04, I have to run the script twice to run all the commands. The first time it stops after smart_script (it creates the log file).
1
vote
2answers
525 views

Why bash does not update Java path without running source ~/.bash_profile?

I am using Mac, and $JAVA_HOME environment path is set in ~/.bash_profile like: export JAVA_HOME=$(/usr/libexec/java_home) After I updated Java, bash kept trying to find Java from the older version. ...
2
votes
1answer
1k views

Combining Bash Script and Script Resources into One Executable

When trying to execute a bash script, it is often execute inside some directory, and requires access to local resources. I was wondering if there was a way to combine both the bash script and the ...
0
votes
2answers
74 views

How can I check if returned value is true in one line?

I'm running the following command in bash: yarn config get workspaces-experimental Which returns the following: true\n \n That is, "true" or "false" followed by two end lines. I want to take this ...
0
votes
2answers
60 views

Find files between two times/hours using find

I will write some context for my problem. I have to deal with a process that runs everyday that creates files in three secuential steps: A, B and C. Files from steps A and C are stored in one folder (...
0
votes
0answers
38 views

Help with bash IF construct [duplicate]

Can someone help me understand what's wrong with this script (ran in cygwin)? $ cat myscript.sh #!/bin/bash if [[ $myfile =~ (.+)-(.+)\.(.+) ]]; then echo "Prefix = ${BASH_REMATCH[1]}" echo "...
-2
votes
2answers
60 views

What am I doing wrong with my own alias in ~/.bash_aliases? [duplicate]

~/.bashrc My ~/.bashrc contains the following (by default): if [ -f ~/.bash_aliases ]; then . ~/.bash_aliases fi ~/.bash_aliases My ~/.bash_aliases contains the following (my definition): ...
4
votes
2answers
758 views

A status bar at bottom of terminal in place of PS1

It occurred to me that when I'm doing stuff in the terminal my PS1 is repeated several times for each command. My PS1 includes CWD and git branch so it can get reasonably long. Is there a way I can ...

1 2 3 4 5 373