I’m writing a Shell script using Bash to convert a Robot Framework resource file from Windows to Linux. The contents of the Resource file itself are not important, but here is the required “minimal, complete, and verifiable example”. beep is a typeless empty file used to test a site’s ability to upload files. There will be an unspecified and ever-changing
Tag: shell
Evaluating command inside bash script leads to increment in $SHLVL
I have the following bash script (myscript.sh): Now: before sourcing myscript.sh, $SHLVL is 2. After sourcing it, is 3. Why? Shouldn’t the command evaluation exit after echo? Thank you! Answer When you source a script in bash, $0 expands to bash (or at least, the name of the shell bash was started as). So $(echo $0) expands first to $(echo
Moves files from directory by reading file names from a text file
I want a script that is able to read the content of a text file which contains folder names and moves the folders from their directory to a specific folder. Here is my script: This script is partly working as it copies only the last folder in the text file, as for the other folders it gives the error “not
How can i give specific commands to programs via terminal Linux?
I’m seeking for a way to automatize the configuration of some tasks i do, but, i am having some trouble to give the order to the programs from the terminal. I have actually to give, every time i try to configure some Routers, the same commands always and always, but, i’m looking for a way to create a Shell Script
Using bash, how can I remove the extensions of all files in a specific directory?
I want to keep the files but remove their extensions. The files do not have the same extension to them. My end goal is to remove all their extensions and change them to one single extension of my choice. I have the second part down. My code so far: Answer You don’t need an external command find for this, but
escape one variable but not the other in awk
I’m facing a problem with awk in Linux. I would like to do make this script work : The problem here is that I want the variable “var” to be interpreted (it works) and the variable $OTHERVAR not to be interpreted, and this I what I can’t manage to do. In the end, I want to do this: I have
Getting the User ID from the last line of the /etc/passwd file in Linux
I’ve been trying the following: and These statements aren’t working, I’m not sure how to join both of them to get the result I want. It just takes the current command that is in front of the /etc/passwd directory. I’m fairly new to Linux and combining commands together. Thank you for the help in advance. Answer Try: Or: Notes The
Split file into multiple when special char met
I have a main file as following : My final goal is to create a file that will containt only block that contains a specific string, for example if that string would be lines then I would have an output file like this : To reach my objective, I first try to split my main file into subfiles by bock
Save only one string of multi-string command output
I’ve got a bash command to find the largest file in a sub-directory. I’d like to save the output to a variable to use it with other commands. bigile=$(find /path/to/directory -type f -exec du -Sh {} + | sort -rh | head -n 1) Unfortunately, this saves both the file size and the filepath. If I pass the variable to
Group the consecutive numbers in shell
In shell, how to group the numbers in $foo as 1-3,6-8,11,13-17 Answer As an alternative, you can use this awk command: Now run it as: Here is an one-liner for doing the same: In this awk command we keep 2 variables: p for storing previous line’s number s for storing start of the range that need to be printed How