Read Mode
Default

Batch Macros II | because "Don't be the same! Be Better!" | by Sounak@9434

Hey everyone, it's been a while since I have posted something. I promised an update to my 'Batch Macros' post but you know, I was a little bit too busy with my schedule. School problems, family problems, girlfriend problems etc. etc. But a few days ago Kvc posted a very inspirational quotation which is...
"Don't be the same!
Be Better!"
Batch Macros II | because "Don't be the same! Be Better!" | by Sounak@9434
Batch Macros II | because "Don't be the same! Be Better!" | by Sounak@9434
That reminds me how much important it is to keep pushing us further as "The world is not going to compromise for you, you have to compromise for the world". So finally here is the part II of Batch Macros.
Read About Part-I of Batch Macros

Batch Macros II | Explanation By Sounak@9434

I have divided this article in basically two parts, depending on the possible types of macros that you can make. s,o without wasting time let's have a look at them. In this part we are going to learn:- 
  • Single Lined Macros
  • Multi Lined Macros
Beware!  A lot of theory in Section.

Single Lined Macros:

As already talked in the last article about batch macros - we have talked about single and macros. so this article is mainly focused on the multi-line macros so let's talk about them.

Multi lined macros:

So far - we have only created macros that are limited to a single line. But, working out all the stuff in the single line soon becomes a pain in the neck (more of a pain in the brain). As we can't just solve all our life problems in a single line! (trust me, we can't)

So, here came the need to use multi-lined macros. But, the stuff wasn't that easy as it seems to be. There is no batch command that works over multiple lines! So what can we do?


In this case, we are using the caret(^) in a very clever way as ^ this sign has a particular effect in the batch programs. so, we are going to use this property of the caret ^ in these multiline macros.

Batch Macros II | because "Don't be the same! Be Better!" | by Sounak@9434


Jeb's post on caret and explaining newline variable (Link to SO)

what we are gonna do is to create a "Line continuation character" a character that continues a line and also expands it when executed. It's a little hard to understand but here is the syntax.


echo Test1
echo one ^
two ^
three ^
four^



--- Output ---

Test1
one two three four



echo Test2
echo one & echo two



--- Output ---

Test2
one
two



echo Test3
echo one & ^
echo two



--- Output ---

Test3
one
two



echo Test4
echo one ^
& echo two



--- Output ---

Test4
one & echo two


And, this little screenshot from the link about the explanation of batch macros - using the caret will definitely help you out in understanding more about these special cases while creating a batch program. If you find any anomaly, or if you want to suggest any other method - you are heartily welcome in the comments with below I will be happy to read your comment.

Batch Macros II | because "Don't be the same! Be Better!" | by Sounak@9434
Batch Macros II | because "Don't be the same! Be Better!" | by Sounak@9434

From Editor's Desk

So, that's all from my side and I hope you will like this article. If you have any doubt, you know you can leave it in the comments and I'll try to help you out. I'll be happy to read your comments. You can also submit your own work to the best team to be published on this website with your name.  thanks your time and faith in TheBATeam. See you in the next article.

1 comment:

Powered by Blogger.