Is it possible to have a single file that acts as both a batch and bash script?
Just a theoretical question. Would it be possible to have a file that simultaneously acts as a batch file for windows and a bash file for *nix?
The way I think it would work is to have a line that is ignored by bash but in Windows jumps to some batch code.
See also questions close to this topic
automate responses on command prompt
Is there any way to automate the installation of this software using shell script? The problem is that I have to press ENTER and type YES twice and I am not sure how to use these 4 steps.
wget https://github.com/conda-forge/miniforge/releases/download/4.8.3-4/Miniforge3-Linux-aarch64.sh bash Miniforge3-Linux-aarch64.sh
When I run the command mentioned above, I have these 4 steps:
press ENTER type YES press ENTER type YES
I want to add this installation as a shell script in docker file or (if possible) directly in dockerfile.
loop through a file 4 rows at the time and store the lines in 4 variables
I'm trying to loop through a file 4 rows at the time and store the lines in 4 variables
8069347 41301052 394971301 39413010 8655766 91557668 754318656682 0279628
Desired Output stores the first 4 rows and after 5s the next 4 rows
8069347 41301052 394971301 39413010
I tried this but it only stores the line in
while read -r a b c d ; do echo "$a" echo "$b" echo "$c" echo "$d" sleep 5 done < Auto
Any idea how to fix this? I'm not opposed to a for-loop option
how to run docker CMD as root after USER was changed
I have a docker image that runs on linux alpine. Sudo is not installed. I would like to build the image with a non-root user but I need to run a start script from CMD as root after the image is build.
I need to open the container in vscode and if the USER is root then all new files created inside the container environment (and mounted in a volume) will be owned by root and therefore needs sudo to modify from the host system.
If I change the USER to anything but root in the Dockerfile, then the start.sh script running in my parent image CMD cannot run.
I have tried a few things like:
- Dockerfile RUN is done as root and the start.sh script ends with: su . to change the user back to the non root. This has no effect on vscode ownership. I can then create new files from the terminal with the non root user, but I would rather be able to use vscode create new file (which is still owned by root)
- Override the CMD to run with sudo (but sudo not installed. And I do not want to install it)
CMD su root -c /start.shbut I dont know the root password in the docker image, and I do not want to modify the root password
Any help with finding a way to run my start.sh script with root privileges without using sudo would be greatly appreciated.
How do I combine multiple inputs that have the same output into a single If statement in the batch choice command?
So I've recently been experimenting with the choice command in batch, and I was wondering if there was a way I could have multiple inputs have the same output, without having an if statement for each one. For example, I'd like to have a simple Y/N choice but have Y and y do the same thing, and N and n do the same thing as well. I realize I could just do this:
IF %Errorlevel% == Y goto :choiceY IF %Errorlevel% == y goto :choiceY IF %Errorlevel% == N goto :choiceN IF %Errorlevel% == n goto :choiceN
However, I was wondering if there was a way to simply combine both inputs into a single If statement, such as:
IF %Errorlevel% == Yy goto :choiceY IF %Errorlevel% == Nn goto :choiceN
So, is there a way? Thank you in advance for any/all help.
Edit: Well I just figured out that the choice command doesnt seem to like lowercase letters anyway, as even when I put all 4 IF statements, as well as /C YyNn, it always seems to go straight to the default error level, without allowing for an input. Since that might be confusing, heres the Choice command im using:
CHOICE /n /T 15 /C YyNn /M "Please type Y to continue, or N to cancel. In 15 seconds, the program will continue automatically." /D Y
Basically, it keeps going straight to the result for Y, without any chance for an input. Does lowercase just not work, or is there something wrong with my choice command?
To make responses easier, here is all the code in the batch file:
@echo off :begin echo. echo. echo This is a test file for batch coding. echo. echo. pause goto :choice :choice cls CHOICE /n /T 15 /C YyNn /M "Please type Y to continue, or N to cancel. In 15 seconds, the program will continue automatically." /D Y IF %Errorlevel% == Y goto :start IF %Errorlevel% == y goto :start IF %Errorlevel% == N goto :end IF %Errorlevel% == n goto :end :start cls echo. echo Your choice was Y. timeout 10>nul exit :end cls echo. echo Your choice was N. timeout 10>nul exit
Moving folders to alphabetically catalogued folders by using a batch-file
I want to move folders to alphabetically catalogued folders by using a batch-file, eg.:
Move folders starting with an "A" to folder "A", folders starting with a "B" to folder "B" etc. Numerical folders have to go to folder "#".
I've come up with this but it only works for files and I can't get it to work for folders. I have to change the %%~A*.* into something else but I don't know into what...
@ECHO ON SET Letters=(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z) SET Numbers=(0,1,2,3,4,5,6,7,8,9) FOR %%A IN %Letters% DO MOVE "%%~A*.*" "%%~A\" FOR %%B IN %Numbers% DO MOVE "%%~B*.*" "#\"
I have created the letter-folders already so creating those folders is not necessary.
What am I doing wrong?
Batch create a Folder in every subfolders and Move all the .jpg files in it
I made this batch file that makes a folder named Pictures and puts all the .jpg files in it.
@echo off md Pictures for %%i in ("*.jpg") do ( move /Y "%%i" "Pictures" ) end
Is there anyway to make it work through subdirectories? I want to run the batch file on a root directory and make it work for all subfolders.