I'm running a bash script in the Embedded Command Line that comes with Quartus II. The bash script was sent to me from someone using linux and I was able to get most of the script to work(removing sudo, changing path, etc.). The only two commands that are still giving me errors are mkfs.ext3 and mkfs.vfat. Are these tucked away somewhere in cygwin that I need to add a path or is there another workaround? I've read some people use mkdofsf but cygwin doesn't appear to have that either.
UPDATE:
Tried using /sbin/mkfs - t vfat and /sbin/mkfs -t ext3 but this left me with a similiar error where mkfs.vfat and mkfs.ext3 were not found.
UPDATE 2: Installed e2fsprogs to solve the error with mkfs.ext3 but this doesn't solve the vfat formatting issue.
These are part of the package e2fsprogs which is available in Cygwin. I've never tried these commands, assuming that access to the raw devices would be blocked by Windows. But I see that cfdisk seems to work. It at least starts up, anyway. So, maybe it is doable.
If they don't work on raw devices, if your scripts are creating file systems on a file or can be modified to do that, that should probably work.
Anyway, e2fsprogs is what you need, but be careful here. Whenever you start making or editing file systems, you have the opportunity to really screw up your system. Just be attentive to what the script is doing, and don't blindly go forward.
Related
I am making a public image on AWS and so am required to 'hide' some shell scripts, but still have them freely usable. We're not looking for the utmost security, I understand SHC can be reverted if a user actually wishes to do so, but it's enough for my requirement.
So that's all good! I have a shell, 'test.sh'. I convert it, 'shc -f test.sh'. The output is a .x and a .x.c file. I run './test.sh.x' - It runs exactly as I expect it to.
So far so good...
But if at any point I reboot the instance, then when I try and run './test.sh.x' again it fails and just outputs a load of random binary stuff.
I have absolutely zero idea what is causing this or why it is causing this. The file is not being edited, or moved, or anything.. It just suddenly does not work anymore. Why?? I've searched online but can't seem to find anyone having this same issue, so any help will be massively appreciated.
And to note, a valid alternative that may not result in the same issue (worth testing at least) is most welcome, as I'm not dead-set on using SHC specifically, it's just the only one I know about currently.
Oooookay, well I unfortunately was never able to fix this issue. Even if I install SHC after I create an instance from my own AMI, and then compile the scripts at this point, the scripts only work until I reboot the system and then they no longer work.
So instead I found a different solution using Bash-Obfuscator, installed and run as follows:
dnf -y install npm nodejs
npm install -g bash-obfuscate
bash-obfuscate test_input.sh -o test_output.sh
And that perfectly does what I needed. There was, however, one thing I quickly learned using Bash-Obfuscator which was quite important - Do NOT have 'echo' commands across multiple lines as it will break your script. The following will break when obfuscated using this command:
echo "Hello
World"
But replacing that with this (which is practically the same thing) works perfectly okay (must be some way the parser is coded):
TEST_VAR="Hello
World"
echo "${TEST_VAR}"
Hope this helps anyone in future.
In the past, we 'which' command to get the info of the relevant software on our computer, Like:
which python
which git
But now it seems don't work on my MacOS Mojave. Is there anything wrong with my setting?
New edition:
The result will turn out to be like this
AA:~ AA$ which python
/usr/bin/which: illegal option -- -
usage: which [-as] program ...
New edition2:
AA:~ AA$ type --all which
which is aliased to `alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
which is /usr/bin/which
AA:~ AA$ type -all python
python is /Users/AA/anaconda3/bin/python
python is /Users/AA/anaconda/bin/python
python is /usr/bin/python
AA:~ AA$
The alias is what causes the error message. Apparently the alias definition is simply erroneous for your system. It's not clear what defined this alias or why; it seems wrong on several levels, so I doubt it's part of the standard install.
You can remove the alias with unalias which; but I'm guessing it's defined in one of your startup files, and should be removed from there - after this point, it should be gone for good the next time you log in.
But anyway, you should not be using which - it's better to accustom yourself to the POSIX standard command type. It was introduced specifically to replace which but it's apparently still hard to eradicate the old command from people's minds.
For me, this was when something from a yarn global upgrade replaced my system's /usr/bin/which.
/usr/bin/which -> ../local/share/.config/yarn/global/node_modules/.bin/which
Since your error message is exactly the same as the text strings inside that program, it is possible that your issue is from a similar source.
console.error('which: illegal option -- ' + flag)
console.error('usage: which [-as] program ...')
"Fixed" with reinstalling which through the system's package manager (e.g. sudo dnf reinstall which). That may now interfere with whatever JavaScript package depended on that, but I plan on removing those globals, so I will not find out.
Better fix: I feel like my system is dirty now and needs all of its bin files checked... Comparing everything in /usr/local/share/.config/yarn/global/node_modules/.bin to see if it has an equivalent in /usr/bin seems like an easy enough way to look for other points of interference.
for x in $(ls /usr/local/share/.config/yarn/global/node_modules/.bin/*); do
ls -l /usr/bin/"$(basename "${x}")"
done
Then those can be checked against the system's package manager with commands like the following. Then reinstalled if needed.
sudo dnf info ...
sudo dnf provides ...
More:
Seems weird to me that it would allow clobbering existing system programs. At the very least, I would expect it to have used /usr/local/bin instead. That extra system and system-like package management seems to be why they have done away with yarn global in yarn 2 (berry).
I have different packages for sudo yarn global list and yarn global list. Maybe using sudo at some point was my mistake?
P.S. Thanks goes to #tripleee, I was unaware of type. I have seen various other ways of attempting to handle different which programs and different versions of which, along with alternatives like test (and others I have forgotten), but type looks worth trying as a replacement.
P.P.S. Annoying to find out that this OS is configured to run tab completion through which.
P.P.P.S. Yes, I know scripting with the output ls is a bad habit.
This question already has an answer here:
How to restore .bash_profile on a mac? None of my unix terminal are working [closed]
(1 answer)
Closed 2 years ago.
I receive this error message each time I launch terminal:
-bash: =/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin: No such file or directory
You have recently edited one of your shell's startup files and introduced an error.
Probably, ls -lart ~/.bashrc ~/.bash_profile ~/.profile will indicate which one -- if one or more is missing, that's no concern, we just want to see which one out of these you have edited recently. Examine the time stamps and try to remember what you did to change one of these files.
The error probably looks something like
$oopsPATH=/usr/local/bin:$PATH
where you meant to say
PATH=/usr/local/bin:$PATH
but without access to your files, we can't know what exactly is supposed to be there, or how you messed it up.
See also https://askubuntu.com/questions/198730/how-to-restore-bashrc-file/198740#198740
In the common case where you have messed up your PATH so that ls and other commands are unavailable (bash: ls: command not found), you can use the full path (/bin/ls pro ls, etc; though obviously, you have to know the correct path) at least until you can restore your configuration.
PATH=/usr/local/bin:/usr/bin:/bin
is probably a good crutch until you can find the correct default for your OS. You can type that at the prompt, or put it in one of your shell's startup files and start a new shell.
On many platforms, you can find the default user dot files in /etc/skel so if that's present (which unfortunately will not be true for Mac OS, but should be there on most Linuxes):
cp -b /etc/skel/.bash_profile $HOME/
will replace your (presumably broken beyond repair) .bash_profile with the system default one. (Omit the -b option if your OS doesn't have it, but then you'll want to back up your file manually before replacing it.)
Update: This fragment near the top of your .bash_profile is erroneous:
#loginPath
=/usr/local/bin:$PATH
Just take it out; it doesn't seem to do anything useful. There seem to be multiple additional fragments from the MacPorts installer which look wrong, too, but they are just comments. (Perhaps somehow they shouldn't be?)
It seems that you are missing a necessary PATH and that is why it is saying no such file or directory. If, for example, you get this error message when typing in python, it would mean either that (1) python isn't installed; or (2) python isn't on your system path.
This question already has an answer here:
How to restore .bash_profile on a mac? None of my unix terminal are working [closed]
(1 answer)
Closed 2 years ago.
I receive this error message each time I launch terminal:
-bash: =/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin: No such file or directory
You have recently edited one of your shell's startup files and introduced an error.
Probably, ls -lart ~/.bashrc ~/.bash_profile ~/.profile will indicate which one -- if one or more is missing, that's no concern, we just want to see which one out of these you have edited recently. Examine the time stamps and try to remember what you did to change one of these files.
The error probably looks something like
$oopsPATH=/usr/local/bin:$PATH
where you meant to say
PATH=/usr/local/bin:$PATH
but without access to your files, we can't know what exactly is supposed to be there, or how you messed it up.
See also https://askubuntu.com/questions/198730/how-to-restore-bashrc-file/198740#198740
In the common case where you have messed up your PATH so that ls and other commands are unavailable (bash: ls: command not found), you can use the full path (/bin/ls pro ls, etc; though obviously, you have to know the correct path) at least until you can restore your configuration.
PATH=/usr/local/bin:/usr/bin:/bin
is probably a good crutch until you can find the correct default for your OS. You can type that at the prompt, or put it in one of your shell's startup files and start a new shell.
On many platforms, you can find the default user dot files in /etc/skel so if that's present (which unfortunately will not be true for Mac OS, but should be there on most Linuxes):
cp -b /etc/skel/.bash_profile $HOME/
will replace your (presumably broken beyond repair) .bash_profile with the system default one. (Omit the -b option if your OS doesn't have it, but then you'll want to back up your file manually before replacing it.)
Update: This fragment near the top of your .bash_profile is erroneous:
#loginPath
=/usr/local/bin:$PATH
Just take it out; it doesn't seem to do anything useful. There seem to be multiple additional fragments from the MacPorts installer which look wrong, too, but they are just comments. (Perhaps somehow they shouldn't be?)
It seems that you are missing a necessary PATH and that is why it is saying no such file or directory. If, for example, you get this error message when typing in python, it would mean either that (1) python isn't installed; or (2) python isn't on your system path.
I am using a bash script to run a number of application (some repeatedly) on a Windows machine through cygwin. The script contains commands to launch those applications, line by line. Most of these applications run for many minutes and many times I have observed that the i+1 th application is not being started even after i th application is completed. In such cases, if I press enter in the cygwin console on which the bash script is running, the next application starts running. Is it because of any issue with bash on cygwin? Or is it an issue with the Windows OS itself? Have any of you observed such an issue with bash + cygwin + Windows?
Thanks.
I think I have seen this before.
Instead of
somecommand
try
somecommand </dev/null
If that doesn't work, try
cmd /c somecommand
Or experiment with other redirections, e.g.
somecommand >/dev/null
Sounds like you may have a problem with your shell script encoding; DOS (and Windows) uses CR+LF line endings, whereas Linux uses LF endings. Try saving the file as LF.
What might also be going on:
When I was running Cygwin on a school laptop, I encountered a dramatic slowing of shell scripts vs. when they were running in a native Linux environment. This was especially apparent when running a configure script from GNU Autotools.
Check your path for slow drives. (From the Cygwin FAQ):
Why is Cygwin suddenly so slow?
If suddenly every command takes a very long time, then something is probably attempting to access a network share. You may have the obsolete //c notation in your PATH or startup files. Using //c means to contact the network server c, which will slow things down tremendously if it does not exist.
You might also want to check whether you have an antivirus program running. Antivirus programs tend to scan every single executable file as it is executed; this can cause problems for even simple shell scripts that run hundreds or even thousands of individual programs before they run their course.
This mailing list post outlines what is needed to pseudo-mount the main /usr/bin directory as cygexec. I'm not sure what that does, but I found it helped.
If you're running a configure script, try the -C option.
Hope this helps!
Occasionally, I'll get this behaviour because I have accidentally deleted the 'she-bang' at the top of the script, that is, deleted the #!/bin/bash on the first line of the script.
It's even more likely for this to happen when a parent shell script calls a child script that has the she-bang missing!
Hope this helps.
A bit of a long shot, but I have seen some similar behaviour previously.
In Windows 2000, if any program running in a command prompt window had some of it's text highlighted by the cursor, it would pause the command running, and you had to press enter or clear the highlighting to get the command prompt to continue executing.
As I said, bit of a long shot, but accidental mouse clicks could be your issue...
Install cygwin with unix style line breaks and forget weird problems like that.
Try saving your script as "the-properly-line-broken-style" for your cygwin. That is, use the style you specified under installation.
Here is some relevant information:
https://stackoverflow.com/a/7048200/657703