Sometimes I see strange usage of dup2() function. For example: It doesn’t even check the return value. What exactly does it do with such arguments? The man dup2 says that if newfd (second argument of dup2) was previously open, it is silently closed before being reused. But the 0 is stdin and why do we even need to do that?
Tag: function
why does grep works when used as a variable and does not when used as a function in linux shell script?
I am trying to use grep as a variable and a function in a bash shell script. I get the desired output when grep is used as an variable. I do not get the desired output when grep is used as an function. The script used for grep as a variable is as below: the out put when we run
How to pass run time arguments to a function in c through a shell script
I have a shell script which has to take arguments from the command line and pass it to a function in C. I tried to search but didn’t find understandable solutions. Kindly help me out. Should the arguments be passed via an option as a command in the shell script? I have a main function like this: How to pass
Is there any drawback to using functions instead of aliases?
Bash functions are more versatile than aliases. For example, they accept parameters. Is there any drawback to going full function style and completely drop aliases, even for simple cases? I can imagine that maybe functions are more resource intensive, but have no data to back that up. Any other reason to keep some of my aliases? They have easier syntax
Bash | pipe to bash function
In the attempt to pipe to a Bash function, I wrote this: However, in another context I am receiving the correct output plus this error message: “Segmentation fault (core dumped)”. Trying to debug it I ask if there is something wrong the way I am writing the code inside the function in order to get STDIN. Thanks a lot. Answer
Making Directory in C Program [closed]
Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 6 years ago. Improve this question For my assignment, I’ve to write a function to create a directory but I’m not allowed to use SYS functions at all! Is there any
What mechanism does gdb use to know where to “finish” a function call?
In gdb, when debugging inside a function, we can use “finish” command to run to the end of a function. My question is: how does gdb know the ending position of a function, especially when there’s no debugging symbol to match source code “{}”? I guess gdb looks for either “leave” or “mov %rbp, %rsp,pop %rbp” under x86 in order
How do I get screen resolution in a shell script on Linux
Environment System: Linux Mint 18 / 19 Cinnamon 64-bit. Shell: dash (POSIX). Question I need to dynamically account for the screen resolution in a POSIX shell script. I prefer a function for re-use. Answer Function Usage
Call a function from the console as an argument
I have a file1.py: Now I want to call file1.battery() from the linux console with python file1.py battery. But I get the error: Answer You can use eval for compiling string like code or use globals and locals: Also, the module can import itself: