Skip to content
Advertisement

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

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

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

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

Advertisement