Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
"Print" seems to have good representation across a lot of programming languages, even in older stuff like Fortran (1957). Why is it that bash (1989) uses echo rather than print for the function that prints to the screen?
Is there some fascinating history of computing story, or something mundane? Is the design decision related to the fact that $ man print gives me information about whatever MAILCAP is?
Little more research, echo appears to have been introduced (as a built-in function) in the original Bourne shell after 1984: https://en.wikipedia.org/wiki/Bourne_shell Apparently, it existed non-built-in before that.
Update from comments (via Wumpus Q. Wumbley): earliest echo reference this thread has found so far is V3 (1972)
Semantically, echo is not the same as what a print statement can be in a programming language. echo is a simple program that outputs the same input it gets, which within bash scripts is very useful for print stuff, but it's not its purpose.
print in most program languages are a shortcut to write to stdout. That happens to print to a console but can also print to a file or to a printer. IMHO, they are conceptually different and can't be comparable.
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
The community reviewed whether to reopen this question 1 year ago and left it closed:
Original close reason(s) were not resolved
Improve this question
One of the ways to write a multi-line string in Ruby is the "here document", or "heredoc", with syntax like:
<<~HEREDOC
My multi-line string
literal goes here!
HEREDOC
My understanding is that any identifier (word) can be used in place of where HEREDOC was used in the above example. (It doesn't have to be the word HEREDOC.)
Is there a documented best practice -- for code readability, and conformity to standards -- for choosing the name to use in a heredoc declaration?
Observations I've made:
The official documentation (as of Ruby v3.0) doesn't seem to advocate any particular best practice. It just states:
You may use any identifier with a heredoc, but all-uppercase identifiers are typically used.
The word SQL seems common when defining a SQL statement -- regardless of the purpose of the statement.
Code examples (including in the official documentation, and in the canonical StackOverflow question on multi-line strings in Ruby linked above) often use HEREDOC, or EOS (presumably meaning "end-of-string" -- even though the identifier appears both at the beginning and end of the string literal).
Sometimes, a word describing the value being stored is used as the heredoc identifier -- as is typically done when declaring a standard variable.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
i'm very new to mac world, and i'm using bash doing some work.
But I'm not clear about the bash command line. It's so different from cmd.
yb_server:~ Aaron$
above is the command line when i start a terminal.
what's the meaning of yb_server?( I used to remember it's originally macintosh, why
it's changing to yb_server, how can i recover?)
what does ~ mean?
what does $ mean?
yb_server is your computer.
: is an arbitrary delimiter.
~ is your home directory (the current directory).
Aaron is you.
$ is "Speak to me, master!" But it is effectively an arbitrary delimiter.
The whole thing is your prompt. Google "bash prompt" for lots of info. Its format is totally up to you. Say echo $PS1 to find out what the format is now. The default is:
\h:\W \u\$
Learning what those symbols mean is left as an exercise for the reader!
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
I want to write bash in a comfortable environment.
I've tried http://www.vim.org/scripts/script.php?script_id=365
But it lacks:
function list
function parameter hint
function description hint
Is there any vim plugin which you use when writing shell script?
Don't forget that Vim is not an IDE (though through its great integration capabilities and plugins, it can appear like one). It is first and foremost a (very powerful) text editor. (There are various blog posts and discussions around that topic, so I spare you further arguments.)
How are function parameter hints supposed to work in Bash scripts? Arguments are simply passed as positional untyped parameters $1 etc., and must be parsed and assigned to variables inside the function.
Likewise, a function description would require some sort of commenting conventions (e.g. tags like Doxygen or Javadoc use); this is not generally used, so don't expect an existing solution.
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 12 years ago.
Improve this question
Is there (or was there ever) any non-trivial language that allows spaces in its variable names?
I am aware of the language Whitespace, but I'm interested in a language that was actually used for something besides demonstration.
I ask this out of pure curiosity.
In a way, yes. Several languages's variable names are really just keys to a higher-level object. Both Coldfusion and Javascript come to mind. In Javascript, you can write foo=bar, but what you've really said is:
window['foo'] = bar;
You could just as easily write
window['i haz a name'] = bar;
The various scopes in Coldfusion can also be treated as either a (dict|hash|associative array) or a name.
Of course, once you've created a name with whitespace, it's harder to access without using the hash lookup syntax.
TSQL will allow you to use whitespace in table and column names aslong as you have it between square braces [ ]
Theres a fantastic article on just what sql will let you get away with here http://www.sqlservercentral.com/blogs/philfactor/archive/2009/08/14/evil-code.aspx
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I'd like to write a code beautifier and i thought of using Ruby to do it. Could someone show me a place to get started? I've seen a lot of code beautifiers online but I've never come across any tutorials on how to write one. Is this a very challenging task for someone who's never undertaken any projects such as writing a compiler, parser, etc. before?
(Is there another langauge which would be more well suited for this kind of task, excluding C/C++?)
Python has an interesting feature - it exposes its own parser to scripts. There are examples that use the AST - abstract syntax tree - and do the pretty printing.
I'm not aware that Ruby exposes its own parser to its scripts in such a way, but there are parsers for Ruby written in Ruby here.
Well... I think the initial steps are what you'd do for any project.
Write a list of requirements.
Describe a user interface to your program, that you like and won't prevent you meeting those requirements.
Now you can write down more of a "code" design, and pick the language that would be easiest for you to meet that design.
Here's some requirements off the top of my head:
Supports code beautifying of these languages: Ruby, Python, Perl
Output code behaves identically to input
Output has consistent use of tabs/spaces
Output has consistent function naming convention
Output has consistent variable naming convention
Output has matching braces and indentation
Make as many as you want, it's your program. ;p I was kidding about the Perl, but I think every language you support is going to add a more work.