New answers tagged

5 votes

setting alias for sourcing a script, to run that script in jenkins with restricted permissions

You have a bash script in /home/user/ and the bash script is myscript you can set an alias to run /home/user/myscript #!/bin/bash echo "WELCOME BASH" Run chmod +x /home/user/myscript ...
0 votes

Looking for a convenient way to create a "constant array"

Some more approaches: a=() repeat 6 a+=18 repeat 9 a+=19 (){a=(${@%.*})} 18.{1..6} 19.{1..9}
0 votes

Looking for a convenient way to create a "constant array"

Repeater for any shell: shuf -rn 5 -e 19 Immediate values can be represented by variables.
  • 2,331
0 votes

Looking for a convenient way to create a "constant array"

Here is a way to do this using only zsh expansions: tl=( ${${:-{1..6}}/*/19} ${${:-{1..9}}/*/18} ) This takes advantage of how zsh performs substitutions with arrays. It creates an array filled with ...
  • 396
2 votes
Accepted

Trapping SIGINT so that the process kills itself

In bash, EXIT traps are invoked regardless of the exit cause. In your case, CtrlC causes the SIGINT trap to run, then when the script kills itself, the EXIT trap runs. As you suspect, the cleanup ...
1 vote

How to extract part of URL from curl response in bash script?

You say you want to extract part of the URL but then you continue by saying that you only want part of that stored in a variable. Extracting part of a value and doing nothing with it doesn't add any ...
  • 101k
5 votes

How to extract part of URL from curl response in bash script?

With GNU grep: $ grep -oP 'https://[^/]+/\d+/\K.*' <<< 'https://www.example.com/1234/text/111?x=999988' text/111?x=999988 Or With Perl: $ perl -nE 'say $& if m@https://[^/]+/\d+/\K.*@' &...
0 votes

how to pass password as a variable to bash command line without displaying it and show it as *****

If you type a command, what you type remains on the screen. You can, with tput, try to delete the line that is above it. #!/bin/bash sleep 5 tput cuu 1 echo "Running: $0 $1 $2 $3 ********* ...
  • 3,727
-1 votes

Zsh script to recursively unrar into a folder with the same name

Did you try the unrar itself? unrar x archive.rar If the archive has directories and subdirectories - they would be recreated.
  • 4,010
1 vote
Accepted

ssh EOF in bash script - how to store value of command?

Fixing up the current way of doing things ssh $USER@server.com << EOF cd /data/dev/${ARK_PATH}/ ./gradlew bootRun --no-daemon LATEST_FOLDER=\$(find . -type d -exec stat --printf="%...
  • 17k
-1 votes

Bash - while read line fails when ffmpeg executed in while body

Maybe a little late, but the problem with ffmpeg is that it reads from standard input as well, consuming data meant for read in the while-read-loop. I had some strange timestamp messup. To solve this ...
0 votes
Accepted

Permission denied with locate command in Shell Script in Oracle Linux?

Remove the dollar sign. When you write $locate the shell looks for the the variable named "locate" not the executable. Because you don't have a variable named "locate" you are ...
0 votes

Change specific settings with gsettings/dconf key. (archlinux, linux-lts-4.19)

You can do it like this: dconf write /com/gexperts/Tilix/profiles/2b7c4080-0ddd-46c5-8f23-563fd3ba789d/custom-command "'python3 $HOME/.pps/pecan.py'" Regarding the string in GVariant format,...
  • 121
0 votes

how to print first word from a string with multiple words without space?

Assuming none of your file names contain newlines then using any awk: printf '%s\n' *.AppImage | awk -F'[.]|-[0-9]' '{print $1}' If they can contain newlines then using GNU awk or any other version ...
  • 27.3k
0 votes

how to print first word from a string with multiple words without space?

Using GNU grep: <INTPUT> | grep -oP '^\D+(?=-\d|\.)' Using Perl: <INPUT> | perl -nE 'say $& if /^\D+(?=-\d|\.)/' Output Altus GitHubDesktop-linux webamp-desktop YTDownloader The ...
2 votes
Accepted

how to print first word from a string with multiple words without space?

Using % to remove suffixes: for f in *.AppImage; do f=${f%.AppImage} echo "${f%%-[0-9]*}" done
  • 1,098
1 vote

how to print first word from a string with multiple words without space?

Using sed (and it's assumed no newline character in the file's name): printf '%s\n' "$fileName" | sed -E 's/(-[0-9].*)?\.AppImage//'
  • 40.3k
0 votes

Simulating Keystrokes to a Telnet process

This works for me. First, I installed the obsolete telnetd and the associated telnet. Then I created two FIFOs (one for input to the telnet command and the other for its output) and started the telnet ...
  • 101k
1 vote
Accepted

How to add time in my script

It seems to me that the filename (or at least the parts that include the version identifiers) are built up in your second script (marked #shared), on the line: BUILTBASENAME="${VERSION_DIST}-${...
  • 80.1k
0 votes

Linux script for file change email notification ( not inotify or any other utility)

but i have to run it manually What really matters is how soon you need the email notification. If it doesn't have to be very quick then a cron job would suffice. Either capture the file modification ...
  • 4,683
0 votes

Is it bad practice to use sed to pass a variable through to another script?

If you don't want an explicit argument, you may be looking for an environment variable. If one you can use exists, it's in the output of env. Otherwise, you may require your users to set a new one. ...
0 votes
Accepted

Is it bad practice to use sed to pass a variable through to another script?

If you can rewrite the script to use parameters instead of script modifications - do so. There are some legitimate or semi-legitimate cases when you want to modify the script: The script can have too ...
  • 4,010
3 votes

Shell script: How to prepend env variable with prefix only if environment variable is defined?

command ${VALUE:+--flag "$VALUE"} This runs command with the option --flag and its option-argument "$VALUE" if the variable VALUE is defined and non-empty. If the variable is ...
  • 312k
3 votes

what are practical uses of stdbuf or nohup?

Let's start with an example without stdbuf. You need 2 terminals because tail -f will block. Terminal 1 touch log_file1 tail -f log_file1 | cut -d " " -f 1 | uniq Terminal 2 echo "A 1&...

Top 50 recent answers are included