My bash code is simply this. I am trying to learn docker but also a newbie with bash scripting. I type in something simple like google.com for the read command but it gives me curl: (3) URL using bad/illegal format or missing URL. Anyone know what I am doing wrong? docker exec -it missingDependencies sh -c “echo ‘Input Website:’; read
Tag: bash
Batch copy and rename multiple files in the same directory
I have 20 files like: Files have a similar format in their names. They begin with 01, and they have 01*AAA*.sh format. I wish to copy and rename files in the same directory, changing the number 01 to 02, 03, 04, and 05: I wish to copy 20 of 01*.sh files to 02*.sh, 03*.sh, and 04*.sh. This will make the
Linux Shell Script – Mounting and Backing Up Files
I’m writing my first shell script. I want to check if a filesystem is mounted. If so, then backup the documents from my main drive to the backup that is mounted. If not, mount the filesystem, then backup the documents. I executed the script, yet all I got was a lot of text. It didn’t perform as I wanted. Did
How to use error validation in Bash for checking an entry in a file
If there is no entry of that species name in the file how do I give the user an error to say not found? Answer The answer to your immediate question is to examine the exit code from grep. But probably also refactor the loop: A better design altogether is probably to make the search term a command-line argument. This
Remove set of special chars from a string using bash script
I need to search for the file path ending with *Tests.cs having multiple directories. I need to display all the file path in spaces instead of new line. Currently, it is displaying as How to remove ./ from each file path and display it as follows? My bash script is: Answer If your structure is consistent as in the example,
How to show error on console while logging it to both log file and console in bash
I am trying to log messages to both console and a log file in a bash script. I am able to log the stdout message both in console and log file but not a stderr. Below is the script and output. Please help. Script: Log file: Console: I want the below error message to be shown in the console as
run a command with a file pattern
I have this file patterns.txt And I want to run a specific command for every pattern like this: I tried to used for loop like this: but i didn’t work Answer The 2 typical approaches are: and Note that I would expect both of those to fail, since scp expects at least 2 arguments. How you want that 2nd argument
Backslash inside an alias not being stored as part of its definition
I’ve got a screen sessions named BedrockServer. I’ve entered the alias like this: But when I type alias, it lists it as and the alias doesn’t work. I’ve tried messing around with the quotes and using backslashes before the quotes and before the dollar sign, but nothing fixes it. Any ideas what I’m doing wrong? Answer Inside single quotes all
not sure what’s the problem with this “regex” in the “grep” shell command
This was my attempt: I’m on hackerRank. I have this file that is delivered to my stdin. I need as a result lines that contains : Answer In a POSIX BRE pattern, when you use a “shorthand character class” like s, w, even in GNU grep, these escape sequences are treated as separate chars, a backslash and a letter. [D]{1,}
Grandchildren and Great-grandchildren of a process
I am trying to get the grandchildren and grand grandchildren PID’S of a certain PID that I pass as an argument. So, I am trying to find the simplest solution possible for a beginner. Now, I used pgrep -P $pid, to find the children of a certain PID, but now that I want to go even deeper, I think I