Bash - How to share constants between scripts? [closed] - bash

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Is there a way to make it so that there isn't a list of constants at the top of every bash script i have? I have a lot of readonly constants for formatting and such but having them at the top of every single one of my scripts takes up space. Is there a way to make a separate script containing all of them and access it or something? or some way to clean it up?

Use a common script that you source in your other scripts.
E.g. source common.sh will execute that file and you may export variables there.
This is also how files like .bashrc and .bash_profile work, it is sourced when you execute bash (the latter when it is a login shell). When you change .bashrc, you can source it again in the running shell for the changes to take effect.

Related

run vbscript mhta [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
i want to run vbscript from mhta
mshta "vbscript:window.close(msgbox("test"))"
WScript or CScript script hosts are not able to run a script if it is not stored in a file. But you can use mshta and the vbscript: protocol to run simple commands.
Anyway, for this case, it is easier to use
msg console "test"
edited to adapt to comments
i've being testing. vbscript parser in the mshta url has to face a lot of limitations. And problems with spaces, concatenation of commands with :, problems with procedure calling as a function but you can not use call keyword as a space is required, ....
The only stable, "easy" way of doing it is to prepare the vbscript to execute as a string, with no spaces inside it, and use the execute method to run it
mshta "vbscript:window.close(execute("msgbox"&chr(32)&"""test"":msgbox"&chr(32)&"""this"&chr(32)&"should"&chr(32)&"work"""))"
mshta "vbscript:window.close(execute("server=CreateObject(""WScript.Shell"").RegRead(""HKEY_CURRENT_USER\Volatile"&chr(32)&"Environment\LOGONSERVER""):For"&chr(32)&"i=1"&chr(32)&"to"&chr(32)&"3:msgbox"&chr(32)&"i"&chr(38)&"server:next"))"

Exporting variables in shell [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have a question. What is the difference between exporting variables with exportcommand and with . (dot) command? Please, explain it clearly
This is somewhat of an apples and oranges question. They are not identical functions.
The export command is used to set variables, so you've got two choices:
variable=value
export variable=value
If you want to run another shell script, you have several choices:
shellScriptName.sh (no prefix or qualifiers)
/bin/sh shellScriptName
. shellScriptName.sh
Variable assignment does just that, sets a variable. The export controls the scope of visibility of the variable you've just set (in particular, does it get exported to child processes).
As for shell scripts, the first two are essentially identical and run a shell script in another process. In that case, any variables set/exported will not be visible in the calling shell. When you use . it sources the shell script as if it were inline in the current shell script /process (like an import) so variable assignments from the child shell are visible in the current shell.

Is there an autocomplete feature for folder and file names in bash? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I need to navigate to a certain directory and then execute a script located there.
I am using cd folder_name to navigate to the next directory.
One folder has a very long name (with white spaces). Is there a way to type only the first few letters and then use a shortcut key to autocomplete with the first matching name, or to navigate through possible matches?
The same if I want to perform a command on a certain file (e.g. chmod XXX file_name), is there a way to get the name to appear after I type a few letters of the filename?
The shell I am using is bash-3.2 in OS X 10.7.4.
Yes, Bash supports auto-completion (personally, it's one of my favorite features). Use the Tab key to complete what you've typed (note that it's case-sensitive). The Advanced Bash-Scripting Guide has a section on an introduction to programmable completion. You can enable completion to complete command names and more!

Why the backslash in bash? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I exported a variable in ~/.bashrc as follows (followed by source ~/.bashrc)
export w=/home/user/workspace/
When I'm on commandline I try to access sub-directories of $w in following way
user$ vi $w/
After this when I hit the tab key, a mysterious backslash appears
user$ vi \$w/
It disables further tab-completion. Why? May not be vi specific as it occurs even with ls.
Bash version 4.2.24(1)-release (i686-pc-linux-gnu)
Running Ubuntu 11.04
Edit
Workaround: Hit Esc+Ctrl+E before hitting tab.
Bash is a little smart, but not that smart. It's not going to be able to expand out your variable, then tab complete to whatever dir that evaluates to. So it's not the backslash "disabling" tab completion, it's the fact that bash can't find any completion suggestions to make.
Given that completion isn't going to help you if you actually do have environment variables in your path, the only way completion could help you at all is if you meant to type a literal dollar sign. I think bash is just being overzealous in trying to complete to something.
Still, I'd call it a bug, since in your case it not only fails to complete, but also changes the meaning of what you've typed.

Identifying and adapting unix-"isms" to the Windows command prompt [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
In the Python Pyramid tutorial, I encountered this phrase:
"Windows users will need to adapt the Unix-isms below to match their environment."
It appears to relate to the "Export" command, but I am not entirely sure. The question therefore, is how do others go about this process of identifying and adapting "Unix-isms"? My only method so far is to see what isn't recognized, and obviously that could be due to different reasons.
Regarding research, I may have found a paywalled explanation for export specifically, but I'm sure there are better resources for adapting these commands.
Thank you!
The $ symbol is a Unix prompt
The ; is a command separator
export sets sets an environment variable, similar to setx
PATH=/path/to/tutorial_workspace/venv/bin:$PATH is modifying the PATH environment variable, similar to PATH=/path/to/tutorial_workspace/venv/bin;%PATH%
which searches the PATH for a program and returns its location.

Resources