How can I repeat the character – n times in shell? I have read and tried this, but this does not work for -. It throws error invalid option. Below is the exact command that I used: Original posted line: printf ‘-%0.s’ {1..100} I also tried escaping – by putting a but in that case it r…
Tag: bash
Run bash whiptail script after login with sudo
I’m creating a virtual machine configuration script using whiptail that I’d like to have automatically start after the user logs in. The thing is, that I don’t want the user to be root, however because the user will need to be able to change things like hostname, ip address, add directories,…
How can I extract the text portion of a binary file in Linux/Bash?
I have a binary file. If I open it with vi, it shows sequences of human-readable text and binary characters. What is the best way to extract the human-readable portion only using Bash? I was thinking, maybe we can do this over a grep or sed pattern? Answer Use the strings utility – that’s exactly …
Bash debug calling stack
I’m using a generic procedure to trap and describe the error or abnormal situations, instead of the usual ‘2>…’ error construct. The idea will be to have a procedure like this simplified version: and then, used as in this example: The issues are: BASH_SOURCE is the running source. T…
Create a heredoc that doesn’t interpret anything
I’m writing a script for a friend who is not experienced with bash. The script generates a backup script, generates a crontab and runs crontab to create a cron job. I want to date these backups, so currently the script (what’s relevant) is: This, however, generates finalCutScript.bash with the dat…
chmod: changing permissions of ‘my_script.sh’: Operation not permitted
when I’m trying to make shell script that error is shown ,what i must do ?? [sudo] password for rehamadel: [rehamadel@localhost bin]$ ls -l my_script.sh Answer Resolving the operation not permitted error: You created the file via: This means, the owner and group of the file is root. You are not allowed …
How to use source command within Jenkins pipeline script
I recently rewrite bash execution command into Jenkins pipeline. The old code is like Now I use pipeline script to wrap the command, like this However, I got an error, as…/.jenkins/script.sh: line 9: source: environment.sh: file not found. When I try to less environment.sh, it display correctly. So I su…
Get a radius of a circle in bash shell
I need to write a script to find radius of a circle and then find the area while the circumference is given The formula is: RADIUS=CIRCUMFERENCE/(2 * PI) The problem is I cant make this formula work because bash doesn’t accept decimal division I read a lot of answers there but still can’t get what…
Get return value of command run in background with pipe and tee command
I want to get the return value of command run in background with pipe so i have below sample code. Output: If i echo the return value from same command then it print correct return value. But if store it in RETVALUE variable then it shows wrong value. Answer The problem is due to the & sign. This puts the
Read stdin in chunks in Bash pipe
I have some shell scripts that works with pipes like such: My bar.sh calls some command line program that can only take a certain number of lines of stdin. Thus, I want foo.sh’s large stdout to be chunked up in N number of lines to make multiple bar.sh calls. Essentially, paginate foo.sh’s stdout …