LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Showing input and output together on the shell (https://www.linuxquestions.org/questions/programming-9/showing-input-and-output-together-on-the-shell-4175682297/)

theuserbl 09-17-2020 02:10 PM

Showing input and output together on the shell
 
How to pipe a file information and bringing it to screen on the same time?

For example I tried out some demos in Swift.
Swift exists as compiler ("swiftc") and as interactive shell ("swift"). And as interactive shell also as interpreter.

If I start it as interactive shell, it looks like the fowllowing example
Code:

$ swift
Welcome to Swift version 5.3 (swift-5.3-RELEASE).
Type :help for assistance.
 1> // Create arrays
 2> var shoppingList = ["catfish", "water", "tulpis"]
shoppingList: [String] = 3 values {
  [0] = "catfish"
  [1] = "water"
  [2] = "tulpis"
}
 3> shoppingList[1] = "bottle of water"
 4> print(shoppingList)
["catfish", "bottle of water", "tulpis"]
 5> :q
$

The interactive shell shows my input part, the output part and some additional information, which existing only in the interactive shell.
This interactive shell is nice, but some examples are very long. But luckyly, they existing all as swift-files.

This one looks like
Code:

$ cat Example.swift
// Create arrays
var shoppingList = ["catfish", "water", "tulpis"]
shoppingList[1] = "bottle of water"
print(shoppingList)
$

This is the code, which I can compile and run
Code:

$ swiftc Example.swift
$ ./Example
["catfish", "bottle of water", "tulpis"]
$

or interpret it
Code:

$ swift Example.swift
["catfish", "bottle of water", "tulpis"]
$

In both cases, it shown me only the output of the running program. Without my part and without the additional information of the interactive shell.

With
Code:

$ swift < Example.swift
Welcome to Swift version 5.3 (swift-5.3-RELEASE).
Type :help for assistance.
shoppingList: [String] = 3 values {
  [0] = "catfish"
  [1] = "water"
  [2] = "tulpis"
}
["catfish", "bottle of water", "tulpis"]
$

and

Code:

$ cat Example.swift | Example.swift
Welcome to Swift version 5.3 (swift-5.3-RELEASE).
Type :help for assistance.
shoppingList: [String] = 3 values {
  [0] = "catfish"
  [1] = "water"
  [2] = "tulpis"
}
["catfish", "bottle of water", "tulpis"]
$

I can see the additional scripting output information, but I still can't see wahat was input, like when I input it myself like on the top of this posting.

So is it possible, to show the parts of the file and the output and the additional information output all together on the screen in the chronological order?

Greetings
theuserbl

NevemTeve 09-17-2020 11:26 PM

Code:

Fn='Example.swf'
cat "$Fn"
swift "$Fn"


theuserbl 09-18-2020 03:41 AM

Quote:

Originally Posted by NevemTeve (Post 6167334)
Code:

Fn='Example.swf'
cat "$Fn"
swift "$Fn"


Thanks for your reply.
But as I said, with » swift "$Fn" « are some parts missing. A » swift < "$Fn" « Is better.
And a » cat "$Fn" && swift < "$Fn" « would output all, but not in the chronological order like in the top of the last posting.

Or to show it you.
This is how a » cat "$Fn" && swift < "$Fn" « looks like


Code:

// Create arrays
var shoppingList = ["catfish", "water", "tulpis"]
shoppingList[1] = "bottle of water"
print(shoppingList)
Welcome to Swift version 5.3 (swift-5.3-RELEASE).
Type :help for assistance.
shoppingList: [String] = 3 values {
  [0] = "catfish"
  [1] = "water"
  [2] = "tulpis"
}
["catfish", "bottle of water", "tulpis"]


But like this I want to see it, that it looks like:

Code:

Welcome to Swift version 5.3 (swift-5.3-RELEASE).
Type :help for assistance.
// Create arrays
var shoppingList = ["catfish", "water", "tulpis"]
shoppingList: [String] = 3 values {
  [0] = "catfish"
  [1] = "water"
  [2] = "tulpis"
}
shoppingList[1] = "bottle of water"
print(shoppingList)
["catfish", "bottle of water", "tulpis"]

Greetings
theuserbl

michaelk 09-18-2020 04:29 AM

I assume you are using a typical desktop distribution. Open the file in a text editor and use the terminal to compile/run your program. Be sure to save changes or they will not be seen from swift. With this method you do not need to run interactive mode.


All times are GMT -5. The time now is 05:57 PM.