Skip to content
Advertisement

Tag: if-statement

using for in loop with sql output

I have a roles.txt file that contains SELECT ROLE_NAME FROM SENTRY_ROLE WHERE ROLE_NAME produces: Im trying to echo all the roles from roles.txt that are not in the sql_output (user in this example). This is what i have so far: Answer That’s not how you iterate over the lines of a file. See http://mywiki.wooledge.org/BashFAQ/001 I would do this, with a

Assigning variable to a variable inside if statement

I am trying to assign a variable from a prompt input choice with no luck. If the user inputs 1, I want target_db_name = “database2”. My code: I have tried creating another if statement with no luck. Answer if $target_db = “1” then won’t work, because what follows if must be a command, not a test expression. Now, the most

Bash – if statement not automatically operating

I’m having a very odd problem with a bash script, written on Ubuntu 17.04 machine. I have a txt file that contains information about people in this fashion: number name surname city state With these infos I have to create an organization system that works by state. For example, with a list like this 123 alan smith new_york NEW_YORK 123

Bash: if statement always succeeding

I have the following if statement to check if a service, newrelic-daemon in this case, is running… The problem is it’s always returning as true, i.e. “New Relic is already running”. Even though when I run the if condition separately… … it returns 0. I expect it to do nothing here as the value returned is =0 but my IF

move single string up into previous row

I have been trying to solve a problem for hours and haven’t found a solution. I am trying to reformat a text file that has been incorrectly parsed. The file format contains a list of names, starting with the last name first, and has a troublesome sole first name on one of the rows as below: I have tried dumping

Syntax error at or near {

I have an assigment where I have to count the number of words in each .c .cc and .h file.The problem is it keeps showing the syntax error at line 8 and 10 at or near { .This is not a finished script!It may have some other problems but I only needed help with the syntax error! Answer Inside an

If a File is Empty, Write Text to First Line

I need to check to see if two files are empty. If they are, then write “-999” to the file, else run an average on the numbers within the file. Here is the coding I’ve been trying to use: Code: Contents of file_all: Answer the appropriate way to check whether a file is empty is using -s not -z (which

execute code only while sys.argv[1] exist

I have this code: and i want execute this piece of code only while sys.argv[1] is exist: if i only start the program without an arguments (python program.py) it’s print this text: I tried “if sys.argv == 1” but doesnt worked. Any solutions? Thanks Answer Now your program will terminate entirely if the user didn’t supply any arguments, rather than

Advertisement