I am very confused on how command-line input works, so for practice I was trying to take the following program down below and produce the same information but just by using command-line input, the only problem is I have no idea where to start  def main():     x = (input("Give me a boolean: ").lower() == 'true')     y = str(input("Give me a string: "))     z = int(input("Give me a number: "))     if x == True:         print (y)         print ("\"",y,"\"",sep="")     else:         print (z*2)    main()
1878
How do I have a Python script that a) can accept user input and how do I make it b) read in arguments if run from the command line?
26600
On the bash command-line, ↑ gives me the previous command. On the command-lines in ipython or matlab, when I type a few characters, ↑ gives me the previously entered command starting with those characters. How can I enable exactly this behaviour in bash? I am aware of more advanced ways of searching through the command-line history, but sometimes a simple way is more convenient.
33475
There is a yes command in unix/linux which basically infinitely prints y to the stdout. What is the point of it, and how is it useful?
22243
I am having difficulty getting a for loop to take user input in the form of an argument to a function I created. #!/bin/bash number1=&quot;$1&quot;    #Assume user input 5 loops=&quot;$2&quot;      #Assume user input 5 if [[ ${number1} &amp;&amp; ${loops} =~ ^-?[0.00-9.99]+$ ]];then    for number2 in {1..${loops}}    do        Product=$(echo &quot;${number1} * ${number2}&quot; | bc -l)        echo &quot;${number1} * ${number2} = ${Product}&quot;        if test ${number2} -eq 7;then            { echo &quot;----------------------&quot;; echo &quot;${number2} is the best number.&quot;; echo &quot;----------------------&quot;; continue; }        elif test ${number2} -eq 11;then            { echo &quot;------------------------------&quot;; echo &quot;${number2} is pretty awesome as well.&quot;; echo &quot;------------------------------&quot;; continue; }            fi     done else    { echo &quot;Please try again with a valid numerical entry.&quot;; exit 1; } fi  This script does not run when the user inputs an integer for the variable &quot;loops&quot;, and any number for &quot;number1&quot;. number1 = 5 in this case. It returns the error:  (standard_in) 1: syntax error 5 * {1..5} = /home/$USER/For_Loop_Multiplication.sh: line 9: test: {1..5}: integer expression expected /home/$USER/For_Loop_Multiplication.sh: line 11: test: {1..5}: integer expression expected  If I instead directly input an end bound on the number of loops directly into the script like the following, and number1 = 5, it runs fine: #!/bin/bash number1=&quot;$1&quot;     #Assume user input 5 if [[ ${number1} =~ ^-?[0.00-9.99]+$ ]];then    for number2 in {1..5}    do        Product=$(echo &quot;${number1} * ${number2}&quot; | bc -l)        echo &quot;${number1} * ${number2} = ${Product}&quot;        if test ${number2} -eq 7;then            { echo &quot;----------------------&quot;; echo &quot;${number2} is the best number.&quot;; echo &quot;----------------------&quot;; continue; }        elif test ${number2} -eq 11;then            { echo &quot;------------------------------&quot;; echo &quot;${number2} is pretty awesome as well.&quot;; echo &quot;------------------------------&quot;; continue; }            fi     done else    { echo &quot;Please try again with a valid numerical entry.&quot;; exit 1; } fi  It returns the result:  5 * 1 = 5 5 * 2 = 10 5 * 3 = 15 5 * 4 = 20 5 * 5 = 25  Essentially what I think is happening is that the script seems to be placing the entire range as the value number2, which is defined as the iterator in the for loop. Since the input for the variable &quot;loops&quot; is an integer, there should be no difference between asking the user for a range and placing it in the loop, or simply setting it as a default when I write the script. However, there apparently is a difference... Any insight into solving this problem is appreciated. Thanks.
14339
I'm currently studying  and Python programming. I just want to know how I would go about executing a Linux command in Python. The commands I want to execute are:  echo 1 &gt; /proc/sys/net/ipv4/ip_forward iptables -t nat -A PREROUTING -p tcp --destination-port 80 -j REDIRECT --to-port 8080   If I just use print in Python and run it in the terminal will it do the same as executing it as if you was typing it yourself and pressing Enter?
5832
I want to write a function in Python that returns different fixed values based on the value of an input index.    In other languages I would use a switch or case statement, but Python does not appear to have a switch statement.  What are the recommended Python solutions in this scenario?
8793
What exactly do *args and **kwargs mean?  According to the Python documentation, from what it seems, it passes in a tuple of arguments.  def foo(hello, *args):     print hello      for each in args:         print each  if __name__ == '__main__':     foo("LOVE", ["lol", "lololol"])   This prints out:  LOVE ['lol', 'lololol']   How do you effectively use them?
11679
What is it for? How do I use it? How is it different from the regular Command Prompt? Is there anything I should know before starting to use it? Any awesome things you can do with it that a super user should know about?
45642
Say I have written two commands, CommandA and CommandB. I wish to have a third command that takes inputs to determines which of the two previous commands to execute. Very naively this how I would try and accomplish this as shown below, however, it does not work.  \newcommand{CommandA}{     \hspace{5mm} } \newcommand{CommandB}{     \vspace{5mm} } \newcommand{C}[1]{     \Command#1 }   So if I call \C{A}, as written I would really execute \CommandA.
47535
How can I poll the keyboard from a console python app?  Specifically, I would like to do something akin to this in the midst of a lot of other I/O activities (socket selects, serial port access, etc.):     while 1:       # doing amazing pythonic embedded stuff       # ...        # periodically do a non-blocking check to see if       # we are being told to do something else       x = keyboard.read(1000, timeout = 0)        if len(x):           # ok, some key got pressed           # do something   What is the correct pythonic way to do this on Windows?  Also, portability to Linux wouldn't be bad, though it's not required.
61157
What are the possible return values from the following command?  import sys print sys.platform   I know there is a lot of possibilities, so I'm mainly interested in the "main" ones (Windows, Linux, Mac OS)
113428
is a simple way to script small GUIs.  Can anyone give a nice example with a button and a text widget. When the button is pressed should a shell command be executed and the output piped to the text widget.  If you have other nice and clean examples for useful tasks, please add them too.
24489
#include &lt;stdio.h&gt; #include &lt;conio.h&gt; main() {     char ch,name[20];     int i=0;     clrscr();     printf("Enter a string:");     while((ch=getch())!='\n')     {         name[i]=ch;         i++;     }     name[i] = '\0';     printf("%s",name); }   When I give "abc" as input and if I press enter it's not working. Can anyone let me know why the condition ch=getch() != '\n' is not becoming false when I press enter? I have also observed that ch is taking \r instead of \n. Kindly let me know. Thanks
113415
While checking the , I found out that it has a --frontend argument that can be passed to the command along with a value. However, the manpage doesn't explain what the argument exactly does, or what are the available values for it.        -f FRONTEND, --frontend=FRONTEND               Run the specified frontend  My assumption is that it to allow us to go through a specific application like the Software Updater or the command-line. Can I find a better description and a list of possible values for that argument?
48268
I have some simple python code that searches files for a string e.g. path=c:\path, where the c:\path part may vary. The current code is:  def find_path(i_file):     lines = open(i_file).readlines()     for line in lines:         if line.startswith("Path="):             return # what to do here in order to get line content after "Path=" ?   What is a simple way to get the text after Path=?
8128
What is the best possible way to check if a string can be represented as a number in Python?   The function I currently have right now is:  def is_number(s):     try:         float(s)         return True     except ValueError:         return False   Which, not only is ugly and slow, seems clunky. However I haven't found a better method because calling float in the main function is even worse.
111379
How do I evaluate or calculate the return value of a command line? For exemple, I count the number of lines with a grep and I want to know if that value is above X. If so, I want to print the number to a file.  Or I want to substract the value of a grep count to another grep count...  How can I manipulate return values that way ?