I have one file test.txt it have already some data named export website_URL and export username=
test.txt
export username= export website_URL= export port=
start.sh
read -p "USERNAME: " username read -p "web_URL: " website_URL read -p "port: " port
here creating new file from test.txt writing data in to data.txt file
old_file="test.txt" new_file="data.txt" cp -f $old_file $new_file sed -i 's/username=*/username=" $new_file sed -i 's/website_URL=*/website_URL=" $new_file
here if I put input to website_URL=”http://stackoverflow.com/questions/6543841/php-cli-getting-input-from-user-and-then-dumping-into-variable-possible” it is failing with sed: -e expression #1, char 71: unknown option to `s’ this error . So I can store any url value in website_URL variable ? Is anything I am missing please let me know because it is able to store value for username and port
Advertisement
Answer
This is because of backslash in URL’s
url=echo $website_URL= | sed -e "s///\\\\//g"
sed -i ‘s/website_URL=*/website_URL=’$url’/’ $new_file
try this it will work in your case.