Mukul Latiyan

Mukul Latiyan

363 Articles Published

Articles by Mukul Latiyan

Page 25 of 37

Return statement in Lua Programming

Mukul Latiyan
Mukul Latiyan
Updated on 01-Dec-2021 5K+ Views

There are certain cases where we want to return a value from a given function so that we can use it later. These return values make use of a return keyword which in turn allows a function to return values.There is an implicit return at the end of any function, so you do not need to use one if your function ends naturally, without returning any value.It should be noted that the return statement is optional; if not specified, the function returns nil.Also, only one return statement is allowed in a function.Syntaxreturn expression/valueNow let’s consider an example where we would ...

Read More

Numeric for in Lua Programming

Mukul Latiyan
Mukul Latiyan
Updated on 01-Dec-2021 1K+ Views

In Lua, there are two types of for loops − the numeric for and the generic for.SyntaxThe numeric for uses the following syntax −for var=exp1, exp2, exp3 do something endIt should be noted that we can write exp1, exp2, exp3 at the same time or we can omit one of them, and the numeric loop will not result in a compile error, though its functionality will change.ExampleLet’s consider a simple variation of a numeric for loop, where we will try to print numbers from 1 to 10.Consider the example shown below −for i = 1, 10 do ...

Read More

Generic for in Lua Programming

Mukul Latiyan
Mukul Latiyan
Updated on 01-Dec-2021 1K+ Views

The generic for in Lua allows us to iterate over the values in an iterator fashion; it is much more powerful even though it looks simple. The Lua library has plenty of iterators, over which we can use the generic for loop.Syntaxfor i, v in pairs(x) do ... ... endThe i in the above syntax denotes the index of the items we are going to iterate over only by one, and the v denotes the actual values of those items. The x is the iterable item over which ...

Read More

How to use chmod recursively on Linux?

Mukul Latiyan
Mukul Latiyan
Updated on 02-Aug-2021 496 Views

You might have been in a scenario where you are using a Linux as your main operating system and then you try to create or edit a file and the Linux terminal responds with something like “Permission deny” error. In typical sense, such an error is related to insufficient permissions that your current user is having and can be solved by setting the correct file permissions or changing the owner.In Linux, the files are controlled through the file permissions, ownership and attributes, which in turn makes sure that only authorized users and processes can access files and directories.Before understanding how ...

Read More

What Linux utility for sorting processes by network usage?

Mukul Latiyan
Mukul Latiyan
Updated on 31-Jul-2021 428 Views

Linux provides the famous top command utility that provides us with all the information about the processes, their time, their respective IDs, how much CPU chunk they are consuming and much more. The only issue with that is the processes are not sorted in any order and the order changes frequently.There are certain cases where we would like the output to be in a sorted manner somehow, like sorted in the sense that the process which is using the most network will be at the top.One such command line program that we can use that will provide us the desired ...

Read More

What's the difference between nohup and ampersand (&) on Linux?

Mukul Latiyan
Mukul Latiyan
Updated on 31-Jul-2021 515 Views

Linux provides us with different utility commands that we can make use of to print a random line from any files in the Unix command line. Mostly we make use of either the shuf command or the sort command, and in this article I’ll explain both the commands and which one is better and why.Shuf CommandThe shuf command in Linux is used to write random permutations of the input lines to the standard output. The idea of randomizing the input is the same as one does when the cards are shuffled. On most of the Linux operating systems it is ...

Read More

Where can I set environment variables that crontab will use?

Mukul Latiyan
Mukul Latiyan
Updated on 31-Jul-2021 1K+ Views

In normal cases we make use of the bash_profile or bashrc in case of Ubuntu and zshrc in case of Mac OS, to set our environment variables and then those variables are made available to us everywhere on the terminal we want.Let’s consider a simple example where we have some environment variable in bash_profile and we are making use of it in the terminal.Consider the bash_profile output shown below −immukul@192 dir1 % cat ~/.bash_profile export JAVA_HOME=$(/usr/libexec/java_home) export PATH=$PATH:/usr/local/node/bin export GOROOT=/usr/local/go export GOPATH=/Users/immukul/go_projectsAs we can see there are many variables present in the bash_profile file, we can use these variables in ...

Read More

What is the sed in-place flag that works both on Mac and Linux?

Mukul Latiyan
Mukul Latiyan
Updated on 31-Jul-2021 4K+ Views

We know that the SED command in Linux stands for stream editor and is mainly used to perform functions on files, and the functions usually are either searching for a word, or replacing it or insertion of something and few more. It is a very useful command and can be found on the Linux kernel.It should also be noted that the BSD (Berkeley Software Distribution) sed shipped with the OS X does need the -i flag to work and the GNU one doesn’t.One way to make the GNU version of the SED to work on the Mac OS X, is ...

Read More

What is the Linux Equivalent to DOS Pause?

Mukul Latiyan
Mukul Latiyan
Updated on 31-Jul-2021 323 Views

We know that the Pause command in DOS is used to suspend execution of the batch files and it then displays the messageStrike a key when ready ...It should also be noted that some versions of DOS also allow a comment to be entered on the same line as PAUSE.ExampleWe can make use of the Pause command in a scenario where we want to suspend the execution of a batch file and display the message “Insert Code”, by typing the following command in the terminalpause Insert CodeSo, that was all about the Pause command in DOS, but we want to ...

Read More

What is fopen() and open() in Linux?

Mukul Latiyan
Mukul Latiyan
Updated on 31-Jul-2021 6K+ Views

The key difference between the fopen() and the open() function in the Linux operating system is that the open() function is a low-level call, where the fopen() when called simply calls the open() function in the background and it returns a Filepointer directly.The call to the open() function includes invoking several other functions and the behaviour of the entire process is mentioned below as a reference to understand the open() function better.Consider the code shown below −int sys_open(const char *filename, int flags, int mode) {    char *tmp = getname(filename);    int fd = get_unused_fd();    struct file *f = ...

Read More
Showing 241–250 of 363 articles
« Prev 1 23 24 25 26 27 37 Next »
Advertisements