All Questions
Tagged with command-line shell
546
questions
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 ...
0
votes
0
answers
11
views
Keyboard doesn't work correctly when booting the linux kernel with single mode from CFE bootloader using UART
I've been encountering a specific and weird bug that i honestly can't seem to find any solution for, i've been toying around with this blu ray player and found a uart port, i wire it to my pi pico ...
0
votes
0
answers
14
views
Run a command, immediately return to the shell prompt, do not return a message when the command is finished [duplicate]
brew install gh > /dev/null 2>&1 &
This returns to the shell immediately, but prints [1] + done brew install gh > /dev/null 2>&1 when the command finishes.
brew install ...
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
56
views
Execute a remote shell script from within screen via SSH and view stdout in one command
Couldn't find an answer for my particular use-case in the hours I've unsuccessfully researched this.
I have a script located on machine B. I am aiming to run a command on machine A that establishes an ...
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
76
views
Why do string variables in a bash script behave differently when echo'ed than they do when passed to an executable?
I have the following script:
#!/bin/bash
KID3=$(command -v kid3-cli)
ARG1="-c 'get'"
file="'1-01 - Johann Strauss - __Waldmeister___ Ouverture.flac'"
echo Command:
echo "$...
0
votes
0
answers
82
views
How to launch another blank terminal in Kali Linux?
When I launch another terminal in Kali Linux with Cmd+Shift+T, I can see Shell No. 2 tab created.
However, it is just a copy of Shell No. 1 and all the commands I ran on Shell No. 1 are visible on ...
2
votes
1
answer
117
views
Execute self-extracting bash script (with binary data appended) w/o saving it first
I have a self-extracting bash script (binary data appended to the end) like this:
#!/bin/bash
export TMPDIR=$(mktemp -d)
ARCHIVE_START_LINE=$(...) # <omitted>
# extracting data archive into a ...
10
votes
4
answers
2k
views
Why does assigning a variable with command substitution, and then echoing that variable, always fail?
Why does the following not work in Bash?
# Ensure TEST is unset
export TEST=''
echo "Hello world!" > test.txt && TEST="$(cat test.txt)" echo "$TEST"
It always ...
0
votes
1
answer
58
views
How to simply cleanup a filename?
OS: Kubuntu 22.04.4 LTS x86_64
to display above:
neofetch --stdout |grep 'OS:'
.
How to simply cleanup a filename, not file contents?
by removing from a filename:
\n newlines
\t tabs
non printable ...
0
votes
2
answers
46
views
An incorrect path is displayed in my custom command line prompt in bash
I would like to display the current and parent directories in my Linux command prompt. For example, if the current directory is /home/user/proj/src, I'd like the prompt to display proj/src.
I found ...
0
votes
0
answers
635
views
How can fzf's command history search always be shown, automatically and without CTRL-R?
With fzf you can press CTRL-R to have a command history search box shown below the prompt and fuzzy search. I want it shown automatically for each new prompt, without having to press CTRL-R.
0
votes
0
answers
43
views
How can I complete individual command line phrases / do partial completion with fzf?
With fzf I can press CTRL-R to search my command history but it completes the whole command. What I'd like is to just complete the current argument, the next phrase before the next space. Can this be ...
0
votes
1
answer
214
views
Is there a shell command that opens multiple images in one instance of the microsoft photos app?
I'm on Windows 11 and let's say I have a folder that contains a few JPEG images. If I navigate to that folder, highlight the images and hit 'enter' it opens all the images in one window of the ...
1
vote
1
answer
614
views
How do I change the background color for folders in PowerShell when invoking the "ls" command from WSL Interop?
I've installed the WslInterop module and exposed several commands from WSL2.
I'm using Import-WslCommand "apt", "cat", "awk", "nano", "find", "...
0
votes
1
answer
281
views
How to nicely print time difference in bash?
In my bash script, I want to print the time that my set of commands took to execute.
I'm doing this:
#!/bin/bash
start=$(date +%s)
./my-long-command.sh
./another-longcommand.sh
echo "Completed, ...
1
vote
0
answers
95
views
Zsh zle function segfaults on `trap 'zle reset-prompt' EXIT`
I have the following function to select a tmux session with fzf:
function tmx {
[ -n "$ZLE_STATE" ] && trap 'zle reset-prompt' EXIT
local tmux item
tmux="$(which ...
1
vote
1
answer
2k
views
Bash shell - shorter way to remove last characters from the file name
I can append a string to a filename without having to enter the repeating part of the command twice:
mv foo{,_bar}
And this renames my foo into foo_bar .
Is there a way to do the opposite - remove ...
0
votes
1
answer
191
views
Linux RHEL 7 - Shell Script - Can execute command separately but cannot execute inside a script
I have a simple script use to install a package under cust privilege like this (command changed for security)
installScript.sh
#!/bin/bash
patch -i <package-name> << EOF
n
EOF
the purpose ...
1
vote
1
answer
393
views
bash: /etc/shells: Permission denied in Ubuntu
I am trying to add Xonsh to my /etc/shellsto make it my new default shell, however when i run sudo which xonsh >> /etc/shells I get bash: /etc/shells: Permission denied I tried changing the ...
1
vote
2
answers
793
views
Unix cat and zip together
What I'm trying to do seems simple enough, but I can't get it to work, nor can I find anything on Google referring to how to do this?
I want to first cat a bunch of files, then zip the resulting file ...
1
vote
1
answer
93
views
zsh completion ( compctl ) does not trig for command names containing dashes
I've used zsh compctl since forever (late 90s or early 00s) but strangly never run into this before.
I realized today when I intended to make some compctl config for update-alternatives that my ...
1
vote
1
answer
10k
views
zsh: event not found: /bin/bash
When I run the following on my command line #!/bin/bash I get the error zsh: event not found: /bin/bash.
I'm on Mac Ventura.
If I run zsh the command works fine, so the issue is with /bin/bash.
Does ...
0
votes
1
answer
367
views
how to chop (truncate) long lines in bash output to fit in the screen with?
I love piping any output into less -S because it prints neatly without wrapping long lines of output into new lines (especially for tables). However, I wonder if there is a way to truncate long lines ...
0
votes
1
answer
396
views
Checking my understanding regarding the difference between Terminal and Shell
I am trying to test my understanding regarding the difference between terminal and shell. The terminal is just a text-based interface in which it accepts commands from the user. Moreover, the terminal ...
0
votes
0
answers
109
views
Batch file using WinSCP won't execute UNIX shell script that assigns variables to output of "more" command
I am working with a Batch script that uses WinSCP to transfer files from an UNIX machine to a windows machine.
To achieve this, WinSCP has to call shell scripts on the UNIX side.
There is one shell ...
1
vote
1
answer
814
views
How do I print a newline after there user enters a password with zshbuiltin read command
I want to read a user's password securely within the execution of a curl command. A made a basic proof of concept which mostly works, but the output of the echo command is coming on the same line as ...
0
votes
1
answer
263
views
How can I make a bash script alias that accepts inputs?
I currently have a bash script that starts up a python file like so
#!/bin/bash
echo "Starting main.py in Production folder"
cd Production
python main.py
main.py is actually supposed to ...
0
votes
2
answers
1k
views
Windows Change Specific Console Color While Program is Running
Is there a command I can run to change a single color in the command line to a different one, during runtime? For example, I can change a color by right clicking on cmd.exe, going into the color tab ...
1
vote
3
answers
980
views
Open terminal to execute command and then terminate if successful
I want to open a terminal and have it accept to execute one command and then terminate (so that the terminal closes). Optionally, this should only happen if the previous command was successful to ...
0
votes
0
answers
540
views
Opening a file using a UWP app from the shell/command line
I need to be able to open certain file types using a UWP app from by using the command shell to pass the file name as a parameter.
The file type I am trying to open with multiple apps is .3mf, used ...
0
votes
0
answers
589
views
Ubuntu 22 - zsh: command not found: lessc
OS: Ubuntu 22.04.1 LTS
zsh 5.8.1 (x86_64-ubuntu-linux-gnu)
Before installing oh-my-zsh everything worked, now I have issues.
One of the issues is zsh: command not found: lessc, but who knows how many ...
0
votes
1
answer
1k
views
Get output logs of previous command in ZSH
I'm working on a helper script that needs to run after every command to analyze its exit status and output logs.
I understand that stdout/stderr buffers are not stored on pseudo terminals. I therefore ...
1
vote
0
answers
319
views
Is there a way to print a commands stdout/stderr only after a given 'timeout'?
Imagine a command which usually takes less than a second to complete an in this case you don't want to get bothered with verbose output, but sometimes it takes longer and in that case you want to have ...
1
vote
1
answer
507
views
Preserve command history in chronological order (in fish)
I have noticed that default behaviour for storing command history is only storing the latest entry.
Typing ls and then ls -al and then entering history would show:
ls -al
ls
Typing ls once more would ...
1
vote
2
answers
3k
views
How do I use xargs to pass arguments as $1, $2, $3, ... to an inline script called with sh -c?
I want to pass tokens a b c as arguments of a script that will output a - b - c.
If I have a script dummy.sh that does echo "$1 - $2 - $3" and a dummy.dat file containing :
a b c
d e f
and ...
2
votes
1
answer
6k
views
Modify 2>&1 so that output goes to a specific file and any errors or other output goes to a log file I can monitor?
I'm reading this post and I don't fully follow the answer.
I wondered if I could modify this, what's it called, command redirect?
What I would like:
Don't hang, use ampersand & to move on to the ...
2
votes
4
answers
2k
views
Run bash scripts without typing the file extension the right way
I'm on Windows 10 and decided to transition from cmd to Git Bash. Say I have a script foo.sh, I'd like to be able to run it with the command foo and not foo.sh. I found this answer, which works in ...
1
vote
1
answer
58
views
apt-get upgrade only those packages which are below 100MB in ubuntu?
Say I want to upgrade all those packages in Ubuntu OS which are below 100 MB.
I need a command for that (in shell), looks like there is no standard command to do that in terminal.
There are multiple ...
1
vote
2
answers
320
views
Works from terminal prompt. How to get bash script working?
using:
Ubuntu 20.04.4 LTS (Focal Fossa)
GNU bash, version 5.1.16(1)
and
script --version
script from util-linux 2.34
These commands are working from a terminal prompt:
script /home/x/Desktop/clamlog2....
0
votes
1
answer
4k
views
Terminal returning error "bash: /usr/bin/(command) /bin/bash: bad interpreter: No such file or directory" unless command is preceded with bash
When I look up this particular error on the web, every single one of them are in regards to shell scripts. I keep getting this error in the terminal itself and my home server is completely unusable ...
1
vote
1
answer
249
views
zsh alias for running the most recent matching history item
I'd like to create an alias in zsh that runs my last terminal command beginning with node. I can run that command with !?node, but I can't create an alias with alias N='!?node'. How can I make this ...
0
votes
2
answers
389
views
Accidentally made an alias for a pre-existing command on OS X
I was toying around with aliases and made an alias to take me to the directory where I store all my bash projects via the cd command.
However, I used 'bash' as a name for the alias. Now when I run all ...
0
votes
1
answer
175
views
Unknown command: `C error displayed when using SED to delete a line in shell script
I am running the below command in a while loop. If my line matches my scenario it will delete that line. I have 2 example 1st one working 2nd one fails.
Can someone point out my mistake?
Example 1 :
...
1
vote
2
answers
6k
views
Can I output `curl` response while also checking for presence of ERROR string?
I have a command I am running with curl. The curl command always resolves successfully even when the server response includes the string ERROR somewhere.
Can I somehow detect this response with some ...
0
votes
1
answer
185
views
Can this mkdir command be simplified with further bash expansion?
I have a command to generate the following directory structure that I need:
./sites
./sites/domain_co_uk
./sites/domain_co_uk/php
./sites/domain_co_uk/cgi
./sites/domain_net
./sites/domain_net/cgi
./...
2
votes
1
answer
1k
views
Having your shell commands run after consecutive ssh
I have a function in my zsh source file ~/.zshrc:
function cr() {
ssh -p 5022 [email protected]
ssh servername2
screen -ls
}
However, everything after the first ssh seems to be ...
-1
votes
1
answer
2k
views
Is there a way to see what command are run on your computer?
I was wondering how I could see the actions that are done on my computer but on my cmd prompt.
For example: Imagine I click on the shortcut Google Chrome on my desktop, then this will appear on my cmd ...
1
vote
1
answer
706
views
How to remove leading file path information from fish shell tab-complete suggestions?
Using fish, typing ls <tab> in an example directory, the terminal displays:
$ ls
bar/ dir/ foo/
Continuing with d<tab><tab> this becomes:
$ ls dir/
dir/moredir/ dir/otherdir/ ...