LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-14-2020, 06:21 AM   #1
Ashiem28
LQ Newbie
 
Registered: Jan 2020
Posts: 4

Rep: Reputation: Disabled
Vim


wondering how to do a certain conditional statement in bash using vim ex if the argument is a 1, the script will echo january.

Last edited by Ashiem28; 04-14-2020 at 06:49 AM. Reason: Need another thread for the other question
 
Old 04-14-2020, 06:36 AM   #2
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
vim and ex are interactive editors. They can't be used to execute statements conditionally or print strings.

To output something conditionally, you can use the if clause:
Code:
if ((arg==1))
then echo january
fi
Or shorter:
Code:
((arg==1)) && echo january
Use the Bash resources in my signature to explore the case statement.

Last edited by berndbausch; 04-14-2020 at 06:38 AM.
 
1 members found this post helpful.
Old 04-14-2020, 07:09 AM   #3
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,670

Rep: Reputation: Disabled
Well, actually Vim can execute scripts with vim -s scriptname.vim. Those scripts have nothing to do with bash though. They are written in Vimscript. It's a full-blown scripting language with conditionals and printing commands among others. For an example of such a script, see your /etc/vimrc or /etc/vim/vimrc (different distros have different conventions as to where they put system-wide Vim configuration).

Or just start Vim like this:
Code:
vim -c 'let arg=1|if arg==1|echo "january"|endif'
and watch the last screen line after start.
 
2 members found this post helpful.
  


Reply



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] Fedora shows 'man vim' but when execute 'vim' got "bash: vim: command not found..." ? flash_os Linux - Newbie 19 01-03-2015 11:56 PM
Switching from vim to vim -g from inside vim iDragoon Linux - Software 4 05-15-2009 11:46 AM
Editor comparison: vim VS vim-lite, Cleaning vim Ruler2112 *BSD 4 04-13-2009 04:26 PM
encryption with Vim (vim -x) mikshaw Linux - Software 2 03-07-2007 09:00 AM
LXer: Cream for Vim - Making Vim more user friendly LXer Syndicated Linux News 0 06-17-2006 11:54 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:43 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