Sponsored Content
Top Forums Programming Python - store output of command to a variable Post 303007512 by apmcd47 on Friday 17th of November 2017 10:15:18 AM
Old 11-17-2017
Try this:
Code:
server_description = "This is xyz abc of mno CentOS"
my_Check = "CentOS" in server_description
if my_Check == True:
    print("This is CentOS")
else:
    print("This is NOT CentOS")

Don't quote the "True". By quoting the "True" you were comparing a Boolean with a string. But the truth is you don't even need that:
Code:
server_description = "This is xyz abc of mno CentOS"
my_Check = "CentOS" in server_description
if my_Check:
    print("This is CentOS")
else:
    print("This is NOT CentOS")

Or even:
Code:
server_description = "This is xyz abc of mno CentOS"
if "CentOS" in server_description:
    print("This is CentOS")
else:
    print("This is NOT CentOS")

As for this:
Code:
>>> server_description = "CentOS"
>>> my_Check = "centos" in server_description
>>> my_Check
False
>>> my_Check = "CentOS" in server_description
>>> my_Check
True

Python is case-sensitive. "centos" is not "CentOS". If you want a case-insensitive string comparison, try:
Code:
"centos".lower() in server_description.lower()

There may be other ways.

Andrew
This User Gave Thanks to apmcd47 For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to store output in variable when put in background

Hi, How do I store following command output: export RESULT=`date` & It works when I do : export RESULT=`date` But what I need is when command put it background, I also need that output going to RESULT variable. Is there any way ? Thanks Sanjay (1 Reply)
Discussion started by: sanjay92
1 Replies

2. Shell Programming and Scripting

To store the output in a variable

Hi, I am getting the following error while executing the script. Please can someone throw some light where is the problem. Many thanks. ./check: temp: not found The directory related to SEP instance 4 does not exist. The script is as follows. SEP_APP="/scp/sepx/app... (2 Replies)
Discussion started by: Sudhakar333
2 Replies

3. Shell Programming and Scripting

How to store the sql query's output in a variable

Hi, My requirement is : We are calling an sql statement from a UNIX session, and fetching data into some variables from a table .. now we are unable to access these variables from outside the SQL part. Please let me know how can I achieve this. Can you please share a code snippet which... (4 Replies)
Discussion started by: venkatesh_sasi
4 Replies

4. Shell Programming and Scripting

ksh: How to store each output line into a different variable?

Example output: /tmp/generatelines.sh line1 line2 line3 line4 I want each output line assigned to its own variable, ie: "line1" --> $a "line2" --> $b "line3" --> $c "line4" --> $d Is this possible without writing to a temporary file? Thanks (4 Replies)
Discussion started by: ksheller
4 Replies

5. Shell Programming and Scripting

store the output of "find" command in a variable?

I intend to find the path/full location of a file(filename given by user thru "read filenme") using "find" or any other command and then store it's output in a variable for some other processing. But struggling to put all things together (i.e finding the fully qualified location of that file and... (4 Replies)
Discussion started by: punitpa
4 Replies

6. Shell Programming and Scripting

remove column and store output to a variable

Hello guys I need to run a script to remove the last column of different comma separated files. The problem is that the number of columns of my files will be different and I won't know that number every time i run my script. Is there any command I can use to remove the last column without... (7 Replies)
Discussion started by: loperam
7 Replies

7. Shell Programming and Scripting

date output store in variable problem

When I run following command date Output1 => Thu Sep 9 03:26:52 IST 2010 When I store in a varibale as a=`date` echo $a output2 => Thu Sep 9 03:27:02 IST 2010 The differnece is, it is trimming the space when I am storing the output in varibale. Output1 = Thu Sep 9 03:26:52 IST 2010... (2 Replies)
Discussion started by: pravincpatil
2 Replies

8. Shell Programming and Scripting

Not able to store command inside a shell variable, and run the variable

Hi, I am trying to do the following thing var='date' $var Above command substitutes date for and in turn runs the date command and i am getting the todays date value. I am trying to do the same thing as following, but facing some problems, unique_host_pro="sed -e ' /#/d'... (3 Replies)
Discussion started by: gvinayagam
3 Replies

9. Shell Programming and Scripting

store sqlplus output in variable

hi how can i store sqlplus output to a variable in sh script (not bash) Thanks MM (1 Reply)
Discussion started by: murtymvvs
1 Replies

10. Shell Programming and Scripting

how to store output to a variable

I need some help: 1) I have a out put from a shell script, the out put looks like this: Attempting privilege escalation using sudo ... List backups for CLTST: Start date Status Ret. Class Label -------------------- ------------ ------------ ... (2 Replies)
Discussion started by: samk
2 Replies
DH_PYSUPPORT(1) 						  python-support						   DH_PYSUPPORT(1)

NAME
dh_pysupport - use the python-support framework to handle Python modules SYNOPSIS
dh_pysupport [debhelper options] [-V X.Y] [-X item [...]] [-n] [module dirs ...] DESCRIPTION
dh_pysupport is a debhelper program that will scan your package, detect public modules in /usr/lib/pythonX.Y/site-packages, and move them to the shared Python modules location. It will generate appropriate postinst/prerm scripts to byte-compile modules installed there for all available python versions. It will also look for private Python modules and will byte-compile them with the current Python version. You may have to list the directories containing private Python modules. If a file named debian/pyversions exists, it is used to determine the python versions with which the package can work. Appropriate dependencies on python-support, python and pythonX.Y are put in ${python:Depends}. The ${python:Versions} and ${python:Provides} optional substitution variables are made available as well. OPTIONS
module dirs If your package installs private python modules in non-standard directories, you can make dh_pysupport check those directories by passing their names on the command line. By default, it will check /usr/lib/$PACKAGE, /usr/share/$PACKAGE, /usr/lib/games/$PACKAGE and /usr/share/games/$PACKAGE -n, --noscripts Do not modify postinst/postrm scripts. -d This option is deprecated. -V X.Y Force private modules to be bytecompiled with the specific X.Y python version, regardless of the default python version on the system. -X item, --exclude=item Exclude files that contain "item" anywhere in their filename from being taken into account to generate the python dependency. It also excludes them from byte-compilation. You may use this option multiple times to build up a list of things to exclude. CONFORMS TO
Python policy as of 2006-08-10 SEE ALSO
debhelper(7) This program is a part of python-support but is made to work with debhelper. AUTHORS
Josselin Mouette <joss@debian.org>, Raphael Hertzog <hertzog@debian.org> 1.0.15 2012-06-30 DH_PYSUPPORT(1)
All times are GMT -4. The time now is 01:27 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy