prompt and read input variables from keyboard

Let's find how to prompt and read input variables from keyboard while executing a script using shell, perl, python, batch and powershell (windows and Linux)




  • On Linux via shell


    read -p "Enter your name: " name
    echo "Hi, $name. Let's be friend!"

Advertisement
  • On Windows via powershell

    $name=read-host "Enter your name:" write-host "Hi $name, Let's be friend!"
  • On Windows via batch

    Set /p Name="Enter your name:" echo "Hi %name%, Let's be friend!"
  • On Windows or Linux via perl

    print "Enter your name "; my $name = ; chomp $name; # Get rid of newline character at the end print "Hello $name, let's be friend";
  • On Windows or Linux via python

    name=input("Enter your name: ") print ("Hello " + name + " let's be friend")

Filed under

Related articles

Level up your Tech Career with DjamgaTech PRO

Download the DjamgaTech PRO App on the Apple App Store to access hundreds of interactive prep questions, flashcards, and quizzes cleanly without ads.

Djamgatech PRO App
Download DjamgaTech PRO on the App Store 🚀

← All articles