PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, November 5, 2022

[FIXED] How to pass multiple variables as input in shell script in non-interactive way

 November 05, 2022     bash, environment-variables, linux, shell     No comments   

Issue

I am trying to make this interactive script take inputs in a non-interactive way by declaring $username and $password variables in bash env and pass them as inputs to the script. By running ./input.sh <<< "$username"

#!bin/bash
read username
read password
echo "The Current User Name is $username"
echo " The  Password is $password"  

is there a way to pass both the variables as input? Because with what I have tried it only takes one input this way.


Solution

Easiest way would be something like that:

#!/bin/bash
echo "The Current User Name is $1"
echo "The Password is $2"

$1 represents the first given argument and $2 the second.

[user@vm ~]$ input.sh "user" "password"

Inside the quotation marks ("") put the argument you want to pass.

For more professional/robust solution check this out: Redhat: Bash Script Options/Arguments



Answered By - Bata94
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

1,209,924

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © 2025 PHPFixing