I’m trying to make a program that simlutates the terminal’s nameless pipes. For example, if I want to run the command: ls –l | grep ‘10’ would be: ./pipes ls -l – grep ’10’ (I use – instead of |). However, my program doesn’t work because execvp fails (bad adress). Thi…
Tag: bash
Validating file records shell script
I have a file with content as follows and want to validate the content as 1.I have entries of rec$NUM and this field should be repeated 7 times only. for example I have rec1.any_attribute this rec1 should come only 7 times in whole file. 2.I need validating script for this. If records for rec$NUM are less tha…
how to auto complete files names on bash script?
I have a bash shell script that cd to directory according to a variable. After that I press Tab and files don’t appear like in terminal. Ex: on read code ups, the files don’t appear when I press tab. Answer The read command requires the -e flag in order to use the readline library to edit the comm…
Bash script unexpected result for while loop
I have following bash script to stop Apache server. I am not getting error but an unexpected result. I got the following answer which I do not expect to be, with an infinite printing: I expect to print: Could anybody please tell me what is happening? Answer This doesn’t work the way you seem to think it…
How does C distinguish between a byte long character and a 2 byte long character?
I have this sample code: First run: Well I think this is all expected as p is 1 byte long character defined in ASCII and I am reading 3 bytes. (2 p’s and Line break) In the terminal, again I see 2 characters. Now let’s try with a character that is 2 bytes long: What I do not understand is,
Why does “/usr/bin/env bash -x” only work in command line?
I am playing with a docker CentOS image, and find executing “/usr/bin/env bash -x” command is OK in terminal: But after writing this command into a script and execute it, it doesn’t work, and prompts “No such file or directory”: Is there any difference between two methods? Answer…
Linux bash printf format with color assign to variable
I just want a String (including coloring) be formatted by printf command and assign the result to a variable. Without assigning it to a variable it works fine, but as soon as I assign the result to a variable and write the result, the format is gone. My example: I found several solutions for passing the resul…
How to send a message to another user via Bash
I am writing a shell script, and I need to send a message to the other user. If I write write user1 in trem, and then write the message and use Ctrl + D, the message will send to user1’s trem successfully. But I want to use a .sh file to send the message to user1 automatically, and I encountered
jq in shellscript: parse argument with ‘-‘
Here’s the json I need to parse: And my code to parse is like the following: The problem is this part: I can’t get the value of it and I guess the reason is that I didn’t pass $var correctly? I also tried But it doesn’t work..Maybe the tiny ‘-‘ in the “config-$valR…
filter file with specift words linux
I have files in which the first column is an ID, and the second column is an option, like this: and I need to create a files with the IDs depending with the option. It is to say: I try with cat file.txt | grep -w “option” > file_option but the problem is that the files are mutually exclusive, a…