All Questions
Tagged with bash-script or shell-script
14 questions from the last 30 days
5
votes
2
answers
828
views
POSIX sh alternative to using [[ ... ]] in Bash
I am using this code to parse the first argument passed to my script. It error handles and it works just the way I want it:
if [ -z "$action" ]; then
printf "[${c_RED}ERROR${c_RESET}...
11
votes
1
answer
1k
views
Is there any difference between [[ -n $1 ]] and [[ $1 ]] in bash?
The test [[ -n $1 ]] yields True if the length of string is non-zero.
But I've seen elsewhere and have tried using just [[ $1 ]] without the primary -n and it seems to have the same effect.
Is there ...
5
votes
1
answer
349
views
zsh - if condition comparison: '-ne' and '!=' have different result
Why these commands lead to opposite comparison results between -ne and !=? Seems != works but -ne does not? I thought they are the same while comparing strings.
% set -o | grep pipe
pipefail ...
2
votes
1
answer
202
views
Replacing the domain string in the compiled binary file with an IP address
Just in theory: is it possible to replace the domain string in the compiled binary file with an IP address by editing a binary file in place with sed? (IP address belongs to a different domain, but ...
1
vote
1
answer
73
views
Bash: only the first long option is being processed
Suppose we have the file ./testing with contents
#!/bin/bash
# Flags
# Source: https://stackoverflow.com/a/7948533/31298396
TEMP=$(getopt -o ''\
--long first,second \
-...
0
votes
4
answers
80
views
Mount a partition from a script unless it is already mounted
I would like to mount a partition of an external hard drive from a script using
udisksctl mount --block-device /dev/sda1
and in the end of the script I would like to unmount it.
However, it may ...
2
votes
1
answer
102
views
Bash: function in a script with flags
Using https://stackoverflow.com/a/7948533/31298396, we can implement flags for a script testing as follows:
#!/bin/bash
# Flags
# Source: https://stackoverflow.com/a/7948533/31298396
TEMP=$(getopt ...
-1
votes
0
answers
65
views
Arch Linux start script
Hi I was just wondering if this script looks ok I run it after I login thanks.
#!/bin/bash
echo "hi, starting wifi, nft and desktop"
sudo ls
sudo systemctl start wpaStart.service
sudo nft -...
0
votes
1
answer
69
views
Bash Script Linux - combines a QUIET function with other functions without hiding some of them
#!/bin/bash
DefaultColor="\033[0m"
GREEN="\033[32m"
RED="\033[31m"
PURPLE="\033[35m"
YELLOW="\033[33m"
CYAN="\033[36m"
CmdOk="\033[...
1
vote
2
answers
56
views
Parent shell script blocked from exiting by background subshell
I have the following script flow:
The parent script is launched from a non-interactive shell and sources a child script.
child launches a background subshell with (...) & and contains no code ...
0
votes
1
answer
52
views
Reading data from serial port on linux [closed]
We have an old setup of a PLC and an old PC (from 90s). The PC previously ran a windows program reading PLC data from a Serial port and plotting it on the monitor. Long story short, the old program no ...
1
vote
2
answers
64
views
Sorting output from find more like tree --dirsfirst -F
Here is a sample directory tree as it would appear if it were sorted in character code order (i.e., directories are not listed first):
${PREFIX}/
.bashrc
.include.sh.d/
common.sh
...
0
votes
1
answer
59
views
LF file manager : how to go back to $OLDPWD?
What do I want :
On the file manager lf, we can bind some keyboard shortcuts to do either a lf command with :, or a shell command with $, !, or other symbols.
According to the documentation, there is ...
0
votes
0
answers
57
views
how to convert hex memory dump to Docsis config file?
Hex memory dump is Docsis config file. Is it possible to convert this hex dump info valid Docsis config file? Preferably, using Perl and DOCSIS::ConfigFile module. (or Python scripts, python-docsis). ...