How do you launch matlab from the linux terminal while also opening a matlab file? - linux

If I want to open file.m in the matlab editor, is there a way to do that directly from the linux terminal?
I can't seem to find the answer anywhere.

Start matlab with the following command to open a file:
matlab -r 'edit <filename>'

Related

Linux how to write a python file without an IDE

Make a copy of a computer python file you wrote for some other course without an IDE just a simple text editor
Modify this program slightly, without using an IDE.
Run the modified program, without using an IDE
How do I create a python file with linux?
To create a python file using Linux use command touch to create a file(will create a file in current directory, to know the current directory use cd command)
touch myfile.py
Open the file using one of the available text editors, for example vi:
vi myfile.py
Type your code and use command :wq to save and close the file.
a=2
b=3
print a+b
Run your code using python command:
python myfile.py
5 #output
To check or install Python on Linux, please refer to AWS detailed instructions: LINK
To get more instructions on using vi editor: LINK
It is as usual with writing c programs and others. No difference at all. If you are familiar with linux command line you can use command line text editors. Otherwise use gedit , sublime text,vs code,atom..etc (all are text editors with GUI) just as you use a notepad in windows.

"Couldn't find a file descriptor referring to the console" on Ubuntu bash on Windows

I have a problem with Bash on Ubuntu on Windows. If I type "open (filename)" on Mac terminal, it opens the file with the right program but if I try to use it on Windows bash, it says: "Couldn't find a file descriptor referring to the console".
I have also tried xdg-open and gnome-open but none of them works. How can the issue be fixed, and how does the open command work?
Instead of open u can use xdg-open which does the same thing, independently of application i.e. pdf, image, etc. It will open a new virtual terminal (I have tried this on Linux)
Example:
xdg-open ~/Pictures/Wallpapers/myPic.jpg
xdg-open ~/Docs/holidays.pdf
For linux, use xdg-open. open is for Mac OS. open in linux is an name alias of openvt (open virtual terminal).
To simplify it, you can append the following line to ~/.bashrc or ~/.zshrc depends on the shell you are using.
alias o="xdg-open" # o stands for open
Then next time you can just type like the following to reduce some keyboard strokes.
o file_name.pdf
That's because open is a Mac specific command, it is not available under Linux (ubuntu), Mac open can execute a file (if the file is executable), or open the file into a text editor (if it is a document or text file) or open a directory.
For opening a file to write in Ubuntu on Windows bash, you can type -:
nano filename.txt
The above command will allow you to write/edit in the file after which, you can use ctrl+x and then press 'y' to save. Check/view the file content using -:
cat filename.txt

SHELL to TXT, Is It Possible?

I created a .sh file in Linux Server and would like to convert it into a text file for windows or Linux mint. Is that possible of doing?
Thank You!!!
In windows right click on it and click "Open with..." and choose notepad.
In mint go to terminal and use either vi or nano to edit the file:
vi /path/to/file/file.sh
Well, not sure if it is what you wanted, but if you have i.e. file named script.sh, you can simply redirect it to another file by executing
cat script.sh > script.txt
However, be aware that EOF in linux is different than in Windows, so you can use this.
just copy the contents from sh file into another file within linux or run this command
cp file.sh file.txt

Default file ending in Mac, Linux and Windows to run executable in the shell/terminal

I created executables of a python script (via pyinstaller) for Mac, Windows and Linux. For Linux and Mac, I am running them in the shell since it doesn't have an own interface: just open a shell and type the name of the program.
I am wondering if there is a way to use certain file ending so if the user clicks on the program, it will be automatically executed in the shell or terminal. Alternatively, I would appreciate any other ideas of how to do this.
The way to do this is not to append a certain file ending, but, as pointed out in the comment, make the file executable (chmod +x <file>) and add the magic bytes to the beginning of the file that tell the system how to execute it.
The magic bytes are #! and are followed by the path to executable. So for a python script you would put something like the following at the top of the file:
#!/usr/bin/env python
Okay, now I finally found out the solution to my question. All you have to do to execute the program upon clicking on it in the file browser is to add the ending .command and make it executable
E.g., exampleprogram.command. Clicking on it will execute the program in the shell

How to compile while gedit is open in gnome?

I am using gcc to compile c code that I am writing in gedit. My problem is that while my .c file is open in gedit, any command I type into my terminal just hangs until gedit is closed. Obviously it is quite cumbersome editing, saving, closing, running, reopening etc. I was wondering how I can have gedit open while compiling so I don't have to close it every time?
Are you launching gedit from that same terminal? This may be a stupid answer, but make sure you're launching gedit with an ampersand, i.e. using the command line gedit &. Without the &, that terminal window won't let you execute additional commands until gedit closes. With the &, gedit runs in the background. Gcc should have no problem compiling a file that's open in an editor. But remember that only the most recent saved version will be seen by gedit, so save your work before trying to compile.
run gedit in background. Like
gedit yourfile &

Resources