LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Vim (https://www.linuxquestions.org/questions/linux-newbie-8/vim-4175673184/)

Ashiem28 04-14-2020 06:21 AM

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.

berndbausch 04-14-2020 06:36 AM

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.

shruggy 04-14-2020 07:09 AM

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.


All times are GMT -5. The time now is 03:21 PM.