LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-17-2020, 02:10 PM   #1
theuserbl
LQ Newbie
 
Registered: Sep 2020
Posts: 2

Rep: Reputation: Disabled
Question 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
 
Old 09-17-2020, 11:26 PM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,852
Blog Entries: 1

Rep: Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868
Code:
Fn='Example.swf'
cat "$Fn"
swift "$Fn"
 
Old 09-18-2020, 03:41 AM   #3
theuserbl
LQ Newbie
 
Registered: Sep 2020
Posts: 2

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by NevemTeve View Post
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

Last edited by theuserbl; 09-18-2020 at 03:47 AM.
 
Old 09-18-2020, 04:29 AM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,594

Rep: Reputation: 5882Reputation: 5882Reputation: 5882Reputation: 5882Reputation: 5882Reputation: 5882Reputation: 5882Reputation: 5882Reputation: 5882Reputation: 5882Reputation: 5882
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Write a shell script that receives a word, an input file and an output file. The scripts copies all the lines in the input file that contain mandy2112 Linux - Newbie 3 08-18-2016 10:11 AM
Passwd command is showing "BAD PASSWORD:" as output but there was nothing after the colon, where there should be some reason output. yogesh95 Linux - Software 4 03-31-2016 07:50 AM
[SOLVED] stty: standard input: Input/output error [bash] DoME69 Programming 7 05-22-2015 12:14 AM
Using shell command output as input in shell script - how to do? EnderX Linux - Newbie 2 06-30-2010 12:46 PM
Repeated "input: AT Translated Set 2 keyboard as /class/input/input" messages AcerKev Mandriva 2 09-16-2007 08:35 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:17 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration