Passing user input value from batch file to shell script
I have a task where I have to write a batch script in which I take input from user and call a shell script from there passing the user input value. Any idea how I can achieve this.
Below is the bat file where I take input from user and finally call the shell script named test(test.sh) which contains curl command
@echo off
set /p technology="Enter technology: "
set /p job_name="Enter job name : "
set /p url="Enter url : "
test.sh
2 answers
-
answered 2022-01-21 08:35
user1934428
Since according to your tags, the shell script is a POSIX shell, and the Batch script is Windows batch, you can take the advantage that Windows puts the variables it sets by default into the environment. Hence the variables should be parameter-expandable inside your shell script as
$technology
etc. -
answered 2022-01-21 11:19
Himanshu Raj
Thank you for your response. The answer I was looking for is
in batch script
@echo off set /p technology="Enter technology: " set /p job_name="Enter job name : " set /p url="Enter url : " test.sh %technology% %job_name% %url%
While in the shell script
echo "technology = $1" echo "job name = $2" echo "url = $3"
The reason for passing value this way is, I wanted to pass value received from user. Here $1, $2, $3 refers to the values passed according to their passed parameters.
While in the shell script with curl command
"url" : "'$3'"
do you know?
how many words do you know
See also questions close to this topic
-
Linux on Lightsail instance is asking for a password and it's not working
I'm trying to restart
mariaDB
on Ubuntu but it's not letting me.I enter:
systemctl restart mariadb
and get:
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units === Authentication is required to restart 'mariadb.service'. Authenticating as: Ubuntu (ubuntu) Password: polkit-agent-helper-1: pam_authenticate failed: Authentication failure ==== AUTHENTICATION FAILED ===
I have the same password for all functions so I do not understand why it is not working. What can I do?
-
How to tag and store files, by metadata, in Python?
I want to build a manual file tagging system like this. Given that a folder contains these files:
data/ budget.xls world_building_budget.txt a.txt b.exe hello_world.dat world_builder.spec
I want to write a tagging system where executing
py -3 tag_tool.py -filter=world -tag="World-Building Tool"
will output
These files were tagged with "World-Building Tool": data/world_building_budget.txt hello_world.dat world_builder.spec
Another example. If I execute:
py -3 tag_tool.py -filter="\.txt" -add_tag="Human Readable"
It will output
These files were tagged with "Human Readable": data/world_building_budget.txt a.txt
I am not asking "Do my homework for me". I want to know what approach I can take to build something this? What data structure should I use? How should I tag contents in a directory?
-
Installing pillow fails on Linux environment or Chrome OS. How do I fix this?
When I try to install pillow with pip3, it gives me the following error message.
failed building wheel for pillow
[omitted text]
Command "/usr/bin/python3 -u -c "import setuptools, tokenize;file='/tmp/pip-install-092vzzoo/pillow/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" install --record /tmp/pip-record-v4rw5g1c/install-record.txt --single-version-externally-managed --compile --user --prefix=" failed with error code 1 in /tmp/pip-install-092vzzoo/pillow/
-
WebView2 JS injection returns empty json string
With WebView2 for targeting Windows, I am trying to setup my own context menu. Either by selected text or by underlying element pointed by mouse click.
However, I can't get DOM element by mouse operation or even by byId. I think my JavaScript injection or WebView property setting is something wrong, but not too sure. Can anyone suggest me the resolution?
The version info.
- OS : Windows 10 Pro 21H2 19044.1682
- Visual Studio : Community 2022 17.1.6
- WebView2 : 1.0.1185.39
- Project Property: Target framework=.NET 6.0; Target OS version=10.0.19041.0
Here's the testing code
using Microsoft.Web.WebView2.Core; namespace WinFormsApp1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); HTML(@"C:\temp\test.html"); } public void HTML(string url) { webView21.CoreWebView2InitializationCompleted += WebView2Control_CoreWebView2InitializationCompleted; webView21.Source = new Uri(url); } private void WebView2Control_CoreWebView2InitializationCompleted(object? sender, CoreWebView2InitializationCompletedEventArgs e) { if (!e.IsSuccess) { MessageBox.Show($"WebView2 creation failed, with exception : {e.InitializationException}"); return; } // subscribe to events we are interested in webView21.CoreWebView2.ContextMenuRequested += CoreWebView2_ContextMenuRequested; // user clicked right mouse to show context menu } private async void CoreWebView2_ContextMenuRequested(object? sender, Microsoft.Web.WebView2.Core.CoreWebView2ContextMenuRequestedEventArgs e) { IList<CoreWebView2ContextMenuItem> menuItemList = e.MenuItems; menuItemList.Clear(); // clear default menu items, like prev, next, property //GETTING SELECTED TEXT string text = e.ContextMenuTarget.HasSelection ? e.ContextMenuTarget.SelectionText : ""; // it works if (string.IsNullOrEmpty(text)) // no text selection, then examine DOM { //GET AN UNDERLYING ELEMENT FROM MOUSE POINT var result = await webView21.CoreWebView2.ExecuteScriptAsync($"document.elementFromPoint({e.Location.X},{e.Location.Y})"); //it doesn't work, just returns an empty JSON text (not null) //var result = await webView21.CoreWebView2.ExecuteScriptAsync("function foo(){return 'foo() gets called';}; foo();"); //for testing purpose, it works //var result = await webView21.CoreWebView2.ExecuteScriptAsync("function foo(){return document.getElementById('table-content'};foo();)"); //it returns an empty result } // TO DO // setup menuItem tree based on the result we got //...... //...... e.Handled = true; } } }
-
site only opens in CefSharp
zaakr.net is a site can be opened only in zaakr.exe application or through android(.apk), when opened in browser u been redirected to https://browser.zaakr.net so u download there application, (.exe) file is using cefsharp as a browser so it can access website, from 2 month i could open it from chromium as cefsharp uses chromium, now i can't access website through chromium for some reason idk, i even made a cefsharp browser myself using visual studio nothing worked all the time i been redirected to browser.zaakr.com, i want to access through any browser that have devtools available for a project, note that application zaakr.exe is still using cefsharp even the older version still can access site. i would appreciate any help, sry for any spelling mistakes, thanks.
-
Subprocess $Env:Path python: The filename, directory name, or volume label syntax is incorrect
I am trying to change the windows environment variables, but I am having trouble doing so.
Before I tried to use
os.environ()
I tried out using powershell commands and adding a string to$Env:Path
which worked, but removing it with:$env:Path = ($env:Path.Split(';') | Where-Object -FilterScript {$_ -ne $Remove}) -join ';'
however didn't seem to remove it being my path I want to add
("FFmpeg:C:\Users\user\AppData\"
) and adding it with+= C:/Users/etc..
didn't see, the way to go.Another way I tried to add vars through the Powershell commands was using
SetEnviormentVariable
and it seemed to work fine but once I restarted my PC the entry I made with it was gone.Sadly though all in the end all my powershell commands didn't work with subprocess. Whatever command it was I was using here I got:
PS C:\Users\Me123> python >>> import subprocess >>> subprocess.run("$Env:Path", shell=True) The filename, directory name, or volume label syntax is incorrect. CompletedProcess(args='$Env:Path', returncode=1)
-
Appending values to existing values of environment variables in go
How can I append another value to an existing value of a go environment variable?
If CGO_CXXFLAGS has the value "-I/blah/blah"
Since the following doesn't work
$ go env -w CGO_CXXFLAGS="$CGO_CXXFLAGS -I/foo/bar"
I want to find a proper way to CGO_CXXFLAGS have the value "-I/blah/blah -I/foo/bar"
by avoiding to simply re-set all the values plus the new one, such as in:
$ go env -w CGO_CXXFLAGS="-I/blah/blah -I/foo/bar"
-
Update global variable from while loop
Having trouble updating my global variable in this shell script. I have read that the variables inside the loops run on a sub shell. Can someone clarify how this works and what steps I should take.
USER_NonRecursiveSum=0.0 while [ $lineCount -le $(($USER_Num)) ] do thisTime="$STimeDuration.$NTimeDuration" USER_NonRecursiveSum=`echo "$USER_NonRecursiveSum + $thisTime" | bc` done
-
How do you use mktemp to create directory in Makefile?
edit:
Solved by awesome answer below. Expand the variables using := instead of =
mktemp: TEST:=$(shell mktemp -d) mktemp: echo $(TEST) touch $(TEST)/test.txt ls $(TEST) cat $(TEST)/test.txt rm -rf $(TEST)
original question:
This is a Makefile piece of code of how someone may use mktemp in a Makefile
TEST=$(shell mktemp -d) mktemp: echo $(TEST) touch $(TEST)/test.txt ls $(TEST) cat $(TEST)/test.txt rm -rf $(TEST)
This is an example output
❯ make mktemp echo /var/folders/62/wkysd_4n0w57ljl9ycfsd9cc0000gn/T/tmp.tQI5EeyW /var/folders/62/wkysd_4n0w57ljl9ycfsd9cc0000gn/T/tmp.tQI5EeyW touch /var/folders/62/wkysd_4n0w57ljl9ycfsd9cc0000gn/T/tmp.lVL3N8Rp/test.txt ls /var/folders/62/wkysd_4n0w57ljl9ycfsd9cc0000gn/T/tmp.sBW9FzgD cat /var/folders/62/wkysd_4n0w57ljl9ycfsd9cc0000gn/T/tmp.Ti53SWSw/test.txt cat: /var/folders/62/wkysd_4n0w57ljl9ycfsd9cc0000gn/T/tmp.Ti53SWSw/test.txt: No such file or directory make: *** [mktemp] Error 1
The expectation is that
cat /var/folders/62/wkysd_4n0w57ljl9ycfsd9cc0000gn/T/tmp.Ti53SWSw/test.txt
would not error.How can mktemp be used in this case?
-
Password-protecting edit privileges using batch files
I have recently been experimenting with Batch files, particularly password-protecting folders in File Explorer. I was just wondering- is there any way to password protect the editing privileges for an individual file? I was just thinking about how easy it would be to change the password of the original Batch file and then just access the hidden files. PS I am using Notepad as the editor for my Batch files.
-
Use GPO/logon script + batch script check app version to trigger action
I want to use GPO deploy log on script for
User Configuration
to check the McAfee app version, If not installed, go to install If already installed, go to skipHere is my script putting on log on script,
@ECHO OFF SETLOCAL set MA_KEY_NAME="HKEY_LOCAL_MACHINE\SOFTWARE\McAfee\Agent" set MA_VALUE_NAME=InstallPath FOR /F "usebackq skip=2 tokens=1,2*" %%A IN ( `REG QUERY %MA_KEY_NAME% /v %MA_VALUE_NAME% 2^>nul`) DO ( set Home="%%C" ) IF DEFINED home SET home=%home:"=% if defined home echo "already installed" if NOT defined Home "\\D:\software\MA_IN.exe -s" exit /b 0
Actually, when script is detected "already installed", I want to check version, when a version >= 5.7.6.251 version go to the end, when a version is low goes to uninstall via command "\\D:\software\MA_UN.exe --noreboot"
I saw detail version in path "C:\Program Files\McAfee\Agent\cmdagent.exe -i", then show output:
Component: McAfee Agent AgentMode: 2 Version: 5.7.6.251 GUID: aa367df5-56d7-4c0e-bd03-cee30124h4e4 TenantId: 665u9-5A79-4ADA-969B-AB3457C1852 LogLocation: C:\ProgramData\McAfee\Agent\logs InstallLocation: C:\Program Files\McAfee\Agent\ CryptoMode: 0 DataLocation: C:\ProgramData\McAfee\Agent\ EpoServerList: ah-usg002.mvision.mcafee.com|ah-gw002.mvision.mcafee.com EpoPortList: 443 EpoServerLastUsed: ah-ghj002.mvision.mcafee.com LastASCTime: 20220507075931 LastPolicyUpdateTime: 20220507075931 EpoVersion: 5.9.0 ServerId: 8F2DFF36F-8663-4205-BB50-92FF4FB04F73
When user AD (not as administrator) logon, the script will be run but not completed because cannot run as administrator, Please help me at all. Many thanks
-
windows batch keep returning a sytax error: cant find the hitch
just want my batch to rotate screen, open a program, and rotate back when closed:
REM starts by rotating the screen using a program called display64 START C:\Users\Admin\Downloads\display\display64.exe /rotate:90 REM then waits a time so the sceen has time to reorient on the monitor. SLEEP 10 REM then launches the game cd "C:\Program Files\Pinball FX2" "Pinball FX2.exe" REM start a loop where the batch seees if the game is running and leaves the screen alone :LOOP ECHO tasklist loop starting tasklist | FIND "Pinball FX2.exe" >nul IF %errorlevel% 1 ( ECHO program not running anymore ---> rotate back! GOTO CONTINUE ) ECHO tasklist loop returned to start ELSE ( ECHO pinfx2 still runnning, restarting loop TIMEOUT /T 5 /Nobreak GOTO LOOP ) ECHO tasklist loop returned showing its closed...stopping loop REM if the program closes, batch rotates the screen back :CONTINUE START C:\Users\Admin\Downloads\display\display64.exe /rotate:0 Exit 0
but I run the batch in a cmd window, with the verbose flag...and this (after forcekilling the game. alt+f4):
C:\Users\Admin\Desktop\launching shorts>"pinfx2 and rotate 90.cmd" -v C:\Users\Admin\Desktop\launching shorts>REM starts by rotating the screen using a program called display64 C:\Users\Admin\Desktop\launching shorts>START C:\Users\Admin\Downloads\display\display64.exe /rotate:90 C:\Users\Admin\Desktop\launching shorts>REM then waits a time so the sceen has time to reorient on the monitor. C:\Users\Admin\Desktop\launching shorts>SLEEP 10 C:\Users\Admin\Desktop\launching shorts>REM then launches the game C:\Users\Admin\Desktop\launching shorts>cd "C:\Program Files\Pinball FX2" C:\Program Files\Pinball FX2>"Pinball FX2.exe" C:\Program Files\Pinball FX2>REM start a loop where the batch seees if the game is running and leaves the screen alone. C:\Program Files\Pinball FX2>tasklist | FIND "Pinball FX2.exe" 1>nul The syntax of the command is incorrect. C:\Program Files\Pinball FX2>IF ERRORLEVEL 1( C:\Program Files\Pinball FX2>
sorry if this seems trivial....I've never had to post before and learned alot of this in the 90s.
-
i used Powershell in a script to execute and install a app in a computer remotly, I Used psexec
well i have a little script this should execute and install one application but really in the other computer hasn't installed i'll want to install application in the other computer
the files txt have the name of the computer yours hostname, when i execute of the script i look that my computer can connect to other computer by psexec and i can watch that appears on my screen in summary "psexec v2... - execute processes remotly, copyright, sysinternals" but after the application has not installed what i can do? i have problems in the last line
& C:\pstools\psexec.exe -u $user -p $password \$destination\c$ $app
$Computers = Get-content "C:\Users\marc\Documents\computer.txt" $destination = Get-content "C:\Users\marc\Documents\destination.txt" $File= "c:\Documents\program.exe" $app="c:\program.exe /clone_wait /s /v' /qn PROGTYPE=ENTEGRA REBOOT=Supress'" Foreach ($destination in $Computers) { $Test = Test-Path -path "\\$destination\c$" If ($Test -eq $True) {Write-Host "The path exists, the software will be installed in $destination."} Else {(Write-Host " the path does not exist, therefore it will be created in $destination and the installation will start")} Echo "Copying Files to C:\$destination" Copy-Item $File "\\$destination\c$" echo "Second part : installing the software on $destination" & C:\pstools\psexec.exe -u $user -p $password \\$destination\c$ $app }
-
Script to double quotes
I have a keyboard that does not have double quotes, when I need to use it, it's very difficult to remember the FN. How can I create a script so that when I press LShift + Escape it puts a double quote?
-
Xpath Changing Dynamically
Stuck at a div dropdown from where i have to count the number of options I am working with a application using selenium java using Maven & testng framework, i am stuck at xpath which is changing on every time i run the test e.g
/html/body/div[7]/div/div/div/div[2]/div[1]/div/div
The div[7] index changes everyTime like it will be differnt next time etc 9, 7
What i tried is to make the xpath dynamic is
//*[normalize-space(text()) and normalize-space(.)='Balochistan'])[1]/following::div[6]
//body//div[@class=\"rc-virtual-list-holder-inner\"]
and few more locator techniques by using this
//body//div[@class=\"rc-virtual-list-holder-inner\"]
I am getting 5 element in which i need the fourth one i tried to use the index along with it but it did not workBelow is the HTML
<div class="rc-virtual-list-holder-inner" style="display: flex; flex-direction: column;"> <div aria-selected="false" class="ant-select-item ant-select-item-option ant-select-item-option-active" title="Please Select"> <div class="ant-select-item-option-content">Please Select</div> <span class="ant-select-item-option-state" unselectable="on" aria-hidden="true" style="user-select: none;"></span> </div> <div aria-selected="false" class="ant-select-item ant-select-item-option" title="abc"> <div class="ant-select-item-option-content"></div> <span class="ant-select-item-option-state" unselectable="on" aria-hidden="true" style="user-select: none;"></span> </div> <div aria-selected="false" class="ant-select-item ant-select-item-option" title="efg"> <div class="ant-select-item-option-content"></div> <span class="ant-select-item-option-state" unselectable="on" aria-hidden="true" style="user-select: none;"></span> </div> <div aria-selected="false" class="ant-select-item ant-select-item-option" title="lol"> <div class="ant-select-item-option-content"></div> <span class="ant-select-item-option-state" unselectable="on" aria-hidden="true" style="user-select: none;"></span> </div> <div aria-selected="false" class="ant-select-item ant-select-item-option" title="lope"> <div class="ant-select-item-option-content"></div> <span class="ant-select-item-option-state" unselectable="on" aria-hidden="true" style="user-select: none;"></span> </div> <div aria-selected="false" class="ant-select-item ant-select-item-option" title="adssa"> <div class="ant-select-item-option-content"></div> <span class="ant-select-item-option-state" unselectable="on" aria-hidden="true" style="user-select: none;"></span> </div> <div aria-selected="false" class="ant-select-item ant-select-item-option" title="ddddd"> <div class="ant-select-item-option-content"></div> <span class="ant-select-item-option-state" unselectable="on" aria-hidden="true" style="user-select: none;"></span> </div> <div aria-selected="false" class="ant-select-item ant-select-item-option" title="e21e12e"> <div class="ant-select-item-option-content"></div> <span class="ant-select-item-option-state" unselectable="on" aria-hidden="true" style="user-select: none;"></span> </div> <div aria-selected="false" class="ant-select-item ant-select-item-option" title="Other"> <div class="ant-select-item-option-content">Other</div> <span class="ant-select-item-option-state" unselectable="on" aria-hidden="true" style="user-select: none;"></span> </div> </div> ```